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

Python 2.7 upload error

mattps New member | Level 2
New member | Level 2

Hi,

 

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(f.read(), file_to)



for jpgfile in os.listdir("/home/pi/pir/captures/jpg"):
    if jpgfile.endswith(".jpg"):
        print datetime.now().strftime("%y/%m/%d %H:%M:%S")+": "+"Uploading capture image."#
        file_from='/home/pi/pir/captures/jpg/180817182433.jpg'
        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 "dp_test.py", line 26, in <module>
upload_file(file_from, file_to)
File "dp_test.py", line 14, in upload_file
dbx.files_upload(f.read(), file_to)
File "/usr/local/lib/python2.7/dist-packages/dropbox/base.py", line 2207, in files_upload
f,
File "/usr/local/lib/python2.7/dist-packages/dropbox/dropbox.py", line 274, in request
timeout=timeout)
File "/usr/local/lib/python2.7/dist-packages/dropbox/dropbox.py", line 365, in request_json_string_with_retry
timeout=timeout)
File "/usr/local/lib/python2.7/dist-packages/dropbox/dropbox.py", line 449, in request_json_string
timeout=timeout,
File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 500, in post
return self.request('POST', url, data=data, json=json, **kwargs)
File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 457, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 569, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python2.7/dist-packages/requests/adapters.py", line 362, in send
timeout=timeout
File "/usr/lib/python2.7/dist-packages/urllib3/connectionpool.py", line 516, in urlopen
body=body, headers=headers)
File "/usr/lib/python2.7/dist-packages/urllib3/connectionpool.py", line 308, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/lib/python2.7/httplib.py", line 1039, in request
self._send_request(method, url, body, headers)
File "/usr/lib/python2.7/httplib.py", line 1073, in _send_request
self.endheaders(body)
File "/usr/lib/python2.7/httplib.py", line 1035, in endheaders
self._send_output(message_body)
File "/usr/lib/python2.7/httplib.py", line 879, in _send_output
self.send(msg)
File "/usr/lib/python2.7/httplib.py", line 855, in send
self.sock.sendall(data)
File "/usr/lib/python2.7/dist-packages/urllib3/contrib/pyopenssl.py", line 208, in sendall
return self.connection.sendall(data)
File "/usr/lib/python2.7/dist-packages/OpenSSL/SSL.py", line 977, in sendall
self._raise_ssl_error(self._ssl, result)
File "/usr/lib/python2.7/dist-packages/OpenSSL/SSL.py", line 849, in _raise_ssl_error
raise WantWriteError()
OpenSSL.SSL.WantWriteError

 

 

Any ideas?

 

Thanks in advance,

Matt

 

 

5 Replies 5

Re: Python 2.7 upload error

Dropboxer
Dropboxer

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 content.dropboxapi.com 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:

 

https://learn.adafruit.com/cloud-cam-connected-raspberry-pi-security-camera/dropbox-sync

 

Re: Python 2.7 upload error

Dropboxer
Dropboxer
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?