Showing results for 
Search instead for 
Did you mean: 
Update: Find information on Dropbox support during COVID-19 here
Showing results for 
Search instead for 
Did you mean: 

Python 2.7 upload error

mattps New member | Level 2
New member | Level 2



This was working up until a few weeks ago and I can't for the life of me see what is wrong - maybe a fresh set of eyes will help.


I am trying to loop through the contents of a directory and upload the unique files to an applicaiton folder in dropbox apps:


import dropbox
import os
from datetime import datetime

access_token = '########################'

def upload_file(file_from, file_to):
    print "Source :"+file_from
    print "Dest   :"+file_to
    dbx = dropbox.Dropbox(access_token)
    f = open(file_from, 'rb')
    dbx.files_upload(, file_to)

for jpgfile in os.listdir("/home/pi/pir/captures/jpg"):
    if jpgfile.endswith(".jpg"):
        print"%y/%m/%d %H:%M:%S")+": "+"Uploading capture image."#
        file_to = '/PIR_APP/180817182433.jpg
upload_file(file_from, file_to)

Note, I have hardcoded the file name for testing purposes.


I get the following error:


Traceback (most recent call last):
File "", line 26, in <module>
upload_file(file_from, file_to)
File "", line 14, in upload_file
dbx.files_upload(, file_to)
File "/usr/local/lib/python2.7/dist-packages/dropbox/", line 2207, in files_upload
File "/usr/local/lib/python2.7/dist-packages/dropbox/", line 274, in request
File "/usr/local/lib/python2.7/dist-packages/dropbox/", line 365, in request_json_string_with_retry
File "/usr/local/lib/python2.7/dist-packages/dropbox/", line 449, in request_json_string
File "/usr/lib/python2.7/dist-packages/requests/", line 500, in post
return self.request('POST', url, data=data, json=json, **kwargs)
File "/usr/lib/python2.7/dist-packages/requests/", line 457, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python2.7/dist-packages/requests/", line 569, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python2.7/dist-packages/requests/", line 362, in send
File "/usr/lib/python2.7/dist-packages/urllib3/", line 516, in urlopen
body=body, headers=headers)
File "/usr/lib/python2.7/dist-packages/urllib3/", line 308, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/lib/python2.7/", line 1039, in request
self._send_request(method, url, body, headers)
File "/usr/lib/python2.7/", line 1073, in _send_request
File "/usr/lib/python2.7/", line 1035, in endheaders
File "/usr/lib/python2.7/", line 879, in _send_output
File "/usr/lib/python2.7/", line 855, in send
File "/usr/lib/python2.7/dist-packages/urllib3/contrib/", line 208, in sendall
return self.connection.sendall(data)
File "/usr/lib/python2.7/dist-packages/OpenSSL/", line 977, in sendall
self._raise_ssl_error(self._ssl, result)
File "/usr/lib/python2.7/dist-packages/OpenSSL/", line 849, in _raise_ssl_error
raise WantWriteError()



Any ideas?


Thanks in advance,




5 Replies 5

Re: Python 2.7 upload error


It looks like this is failing at a much lower level than the Dropbox SDK, so I'm afraid I can't offer too much insight. For reference, here's the documentation for the 'OpenSSL.SSL.WantWriteError' error.


Your Dropbox code looks fine though, and I just tried it and it worked for me (when putting in a valid path on my computer).


A few thoughts to try to narrow this down:

- Is there anything on the network connection, e.g., firewall, proxy, etc., that may be interfering with the Dropbox API HTTPS connection (to in particular, for uploads)?

- Does this happen only for specific file(s), or any files?

- Does downloading work?

- Does getting metadata work (e.g., files_list_folder or files_get_metadata)?

- Did you change/update any libraries when this broke?

- Have you tried this on another computer, and if so does this issue reproduce elsewhere?

Re: Python 2.7 upload error

mattps New member | Level 2
New member | Level 2

A bit more testing...


I fi I cange the file type filter to ".py" and remove the hardcoded filenames it works and the files get uploaded. So the DropBox API doesn't work with JPG files anymore???? 

Re: Python 2.7 upload error

mattps New member | Level 2
New member | Level 2

I may have done an update (sudo get-apt update) recently, I can't remember.

Re: Python 2.7 upload error

mattps New member | Level 2
New member | Level 2

Thanks for the link but I'm going to try the following as a workaround:


Re: Python 2.7 upload error

The Dropbox API certainly still works with .jpg files. (I tested your code with a .jpg file in fact.)

At the layer where this is failing, the file type shouldn't matter anyway. It may have to do with the file size though. Perhaps try to different sizes to verify that?

Otherwise, it if you did do an update, it may be a bug in one of those lower level libraries.

Work Smarter with Dropbox

The way we work is changing. Share and discover new ways to work smarter with Dropbox in our community.

Sound good? Let's get started.
Who's talking

Top contributors to this post

What do Dropbox user levels mean?
Need more support?