def get_item_url(itemid, itemtype):
if itemtype=="folder" or itemtype=="FOLDER":
url = "https://api.box.com/2.0/folders/"+itemid
headers = {'Authorization' : 'BoxAuth api_key='+apikey+'&auth_token='+auth_token,}
payload = {'shared_link': {'access': 'Open'}}
r = requests.request("PUT", url, None, json.dumps(payload), headers)
print r.content
return r.content
elif itemtype=="file" or itemtype=="FILE":
url = "https://api.box.com/2.0/files/"+itemid
headers = {'Authorization' : 'BoxAuth api_key='+apikey+'&auth_token='+auth_token,}
payload = {'shared_link': {'access': 'Open'}}
r = requests.request("PUT", url, None, json.dumps(payload), headers)
print r.content
return r.content
这是我必须获取项目 url 的代码,文件或文件夹取决于传递给方法的字符串。但这不起作用,Box API 总是返回“无效 JSON”错误。谁能帮帮我,我什么都试过了!我尝试使用双引号、单引号,只放置“有效负载”而不是通过 json.dumps 运行它。我已经尝试将它添加为另一个标题,一切,但我无法让它工作!
我也尝试过对 httpbin.org/put 做同样的请求,这就是我得到的回报:
{
"origin": "10.217.61.17",
"files": {},
"form": {},
"url": "http://httpbin.org/put",
"args": {},
"headers": {
"Content-Length": "",
"Accept-Encoding": "identity, deflate, compress, gzip",
"Accept": "*/*",
"Host": "httpbin.org",
"Content-Type": "",
"Authorization": "BoxAuth api_key=<API_KEY>&auth_token=<AUTH_TOKEN>"
},
"json": null,
"data": ""
}