curl to python 请求转换
curl to python requests conversion
我正在使用 Dropbox 的 python API,试图将以下 curl 命令转换为 Python 请求:
curl -X POST https://content.dropboxapi.com/2/files/download \
--header "Authorization: Bearer <ACCESS_TOKEN>" \
--header "Dropbox-API-Arg: {\"path\": \"/Homework/math/Prime_Numbers.txt\"}"
我目前的翻译:
downloadHeader={"Authorization: " + authorization}
downloadURL = "https://content.dropboxapi.com/2/files/download"
downloadPayload = {"Dropbox-API-Arg": {"path": "/" + dbPATH}}
downloadResponse = requests.post(downloadURL, data=json.dumps(downloadPayload), headers=downloadHeader)
但是,当我 运行 这样做时,出现以下错误:
for header in headers.items():
AttributeError: 'set' object has no attribute 'items'
有人可以给我一些反馈吗?我对我的授权值很有信心,因为它在一个单独的请求中工作,我在下面复制并粘贴该请求:
MDlink = "https://api.dropboxapi.com/2/sharing/get_shared_link_metadata"
authorization = "Bearer " + ACCESS_TOKEN
headers={"Content-Type":"application/json", "Authorization": authorization}
payload = {"url": imageLink}
response = requests.request("POST", MDlink, data=json.dumps(payload), headers=headers)
非常感谢!
你想要这个
downloadHeader={"Authorization: " + authorization}
成为
downloadHeader={"Authorization": authorization}
或者更准确地说
downloadHeader={"Authorization": "Bearer <ACCESS_TOKEN>"}
解释:
{1} # this is a set. It has no .items()
{1: 1} # this is a dict. You can call .items()
我正在使用 Dropbox 的 python API,试图将以下 curl 命令转换为 Python 请求:
curl -X POST https://content.dropboxapi.com/2/files/download \
--header "Authorization: Bearer <ACCESS_TOKEN>" \
--header "Dropbox-API-Arg: {\"path\": \"/Homework/math/Prime_Numbers.txt\"}"
我目前的翻译:
downloadHeader={"Authorization: " + authorization}
downloadURL = "https://content.dropboxapi.com/2/files/download"
downloadPayload = {"Dropbox-API-Arg": {"path": "/" + dbPATH}}
downloadResponse = requests.post(downloadURL, data=json.dumps(downloadPayload), headers=downloadHeader)
但是,当我 运行 这样做时,出现以下错误:
for header in headers.items(): AttributeError: 'set' object has no attribute 'items'
有人可以给我一些反馈吗?我对我的授权值很有信心,因为它在一个单独的请求中工作,我在下面复制并粘贴该请求:
MDlink = "https://api.dropboxapi.com/2/sharing/get_shared_link_metadata"
authorization = "Bearer " + ACCESS_TOKEN
headers={"Content-Type":"application/json", "Authorization": authorization}
payload = {"url": imageLink}
response = requests.request("POST", MDlink, data=json.dumps(payload), headers=headers)
非常感谢!
你想要这个
downloadHeader={"Authorization: " + authorization}
成为
downloadHeader={"Authorization": authorization}
或者更准确地说
downloadHeader={"Authorization": "Bearer <ACCESS_TOKEN>"}
解释:
{1} # this is a set. It has no .items()
{1: 1} # this is a dict. You can call .items()