我如何使用访问令牌将文件上传到Dropbox的在Python?
我已经用下面的代码试图要上传的文件
import requests
import json
print("uploading")
token ='#######'
para = {"path": "folder/file.txt", "mode": "add", "autorename": "true", "mute": "false", "strict_conflict": "false"}
headers = {'Authorization': 'Bearer ' + token}
files = {'data': ('metadata', json.dumps(para), 'application/json; charset=UTF-8'), 'file': open("file.txt", "rb")}
response = requests.post("https://content.dropboxapi.com/2/files/upload", headers=headers, files=files)
我在这样的反应得到了一个错误:
错误调用API函数“文件/上传”:必须提供HTTP报头“的Dropbox-API精氨酸”或URL参数“ARG”。
我如何可以修改的代码?
添加下列头和读docs更新必要的头你的要求:
import json
headers["Dropbox-API-Arg"] = json.dumps({"path": "folder/file.txt", "mode": "add", "autorename": true, "mute": false, "strict_conflict": false})
headers["Content-Type"] = "application/octet-stream"