Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
Hi,
I am unable to upload using your Files_upload function. It fails with the following error:
requests.exceptions.ConnectionError: ('Connection aborted.', BadStatusLine("''",))
I am on Windows 7 Pro 64 bit. Using Python 2.7.11. I installed upgrades to dropbox (6.2 six-1.10.0) and Requests (2.10.0).
I can replicate the problem with your back-up-and-restore example program.
My app at dropbox is in development status. Permission type = App Folder. I generated an access token to use while developing.
My token seems ok. If I extend the demo program with a for loop to list files in my directory, it lists the files which I manually placed in there.
Also the following creates a text file in my app folder (the text file sent to dropbox contains just the string 'my-file.txt' ... ? is this working as designed? ... I assumed that it would have sent the file named 'my-file.txt'?)... anyway the text file is created at DropBox ok.
dbx.files_upload('my-file.txt', BACKUPPATH2, mode=WriteMode('overwrite'))
But when I try with any file object in the first operand it times out after (exactly) 1 minute with the above error message.
with open(LOCALFILE, 'r') as f:
# We use WriteMode=overwrite to make sure that the settings in the file
# are changed on upload
print("Uploading " + LOCALFILE + " to Dropbox as " + BACKUPPATH + "...")
What can I do to analyse the problem? Is there some config required at the router etc. ... I have tried with my firewall off. I have no problem dragging files to DropBox or FTPing large files etc
Thanks
Update: Code from here https://dropbox.github.io/dropbox-api-v2-explorer/#files_upload works in my environment. ie.:
import requests
import json
url = "https://content.dropboxapi.com/2/files/upload"
headers = {
"Authorization": "<redacted>",
"Content-Type": "application/octet-stream",
"Dropbox-API-Arg": "{\"path\":\"/xxxxx3\",\"mode\":{\".tag\":\"overwrite\"}}"
}
data = open("My_File.txt", "rb").read()
r = requests.post(url, headers=headers, data=data)
But still no joy using your python SDK ... any ideas?
Hi Barry, the first parameter to files_upload should be "A string or file-like obj of data.". That's the data that gets uploaded. So, if you want to upload a file, you need to open the file and supply the object (not just the path), as you have in your latter examples.
As far as the BadStatusLine issue is concerned, can you try opening the file in binary mode and let me know if that doesn't help? I.e.:
with open(LOCALFILE, 'rb') as f:
thanks for your assistance Gregory
<< As far as the BadStatusLine issue is concerned, can you try opening the file in binary mode and let me know if that doesn't help?>>
Yes, that fixed it. Who should be advised that the Python example program which is provided has a bug? Statement 21 at https://github.com/dropbox/dropbox-sdk-python/blob/master/example/back-up-and-restore/backup-and-res...
Also, could the error handling be improved? The current exception is not helpful to identify the problem.
<<the first parameter to files_upload should be "A string or file-like obj of data.">>
Yes, I had read that. The documentation could be improved IMO. The name of the function is files-upload. My error I know, but I was blind-sided by that, and was thinking that the function only dealt with files.
Great, and thanks for letting me know. We'll get it fixed up.
Hi there!
If you need more help you can view your support options (expected response time for a ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!