How can I upload files to Dropbox in python using access tokens?
I have tried with the following code for uploading the file
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)
I got an error in response like this:
Error in call to API function "files/upload": Must provide HTTP header "Dropbox-API-Arg" or URL parameter "arg".
How can I modify the code for that?
Add the following header and read the docs to update your request with the necessary headers:
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"