Learn how to make the most out of the Dropbox Community here 💙. 

Forum Discussion

Apollonius's avatar
Apollonius
Explorer | Level 4
7 years ago
Solved

Error while uploading a zip file using Python script

 I'm trying to write a Python script where there would be a list of "paths" to files and they would serially be uploaded to my Dropbox.

 

I thought of uploading a directory as a Zip archive if the list contains such an element. It's just a silly project but just for learning purposes. I'm using a shell script to Zip that archive that's called from the Python Script( I know I can do that using Python alone, but this just makes things more interesting!:grin:).

Here are the links to my code: Python scriptBash script

 

And I'm getting the following errors:

 

Traceback (most recent call last):
File "/home/sakib/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 600, in urlopen
chunked=chunked)
File "/home/sakib/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 354, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/lib/python3.6/http/client.py", line 1239, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/lib/python3.6/http/client.py", line 1285, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/lib/python3.6/http/client.py", line 1234, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/lib/python3.6/http/client.py", line 1065, in _send_output
self.send(chunk)
File "/usr/lib/python3.6/http/client.py", line 986, in send
self.sock.sendall(data)
File "/usr/lib/python3.6/ssl.py", line 972, in sendall
v = self.send(byte_view[count:])
File "/usr/lib/python3.6/ssl.py", line 941, in send
return self._sslobj.write(data)
File "/usr/lib/python3.6/ssl.py", line 642, in write
return self._sslobj.write(data)
socket.timeout: The write operation timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/sakib/.local/lib/python3.6/site-packages/requests/adapters.py", line 445, in send
timeout=timeout
File "/home/sakib/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 638, in urlopen
_stacktrace=sys.exc_info()[2])
File "/home/sakib/.local/lib/python3.6/site-packages/urllib3/util/retry.py", line 367, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/home/sakib/.local/lib/python3.6/site-packages/urllib3/packages/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/home/sakib/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 600, in urlopen
chunked=chunked)
File "/home/sakib/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 354, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/lib/python3.6/http/client.py", line 1239, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/lib/python3.6/http/client.py", line 1285, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/lib/python3.6/http/client.py", line 1234, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/lib/python3.6/http/client.py", line 1065, in _send_output
self.send(chunk)
File "/usr/lib/python3.6/http/client.py", line 986, in send
self.sock.sendall(data)
File "/usr/lib/python3.6/ssl.py", line 972, in sendall
v = self.send(byte_view[count:])
File "/usr/lib/python3.6/ssl.py", line 941, in send
return self._sslobj.write(data)
File "/usr/lib/python3.6/ssl.py", line 642, in write
return self._sslobj.write(data)
urllib3.exceptions.ProtocolError: ('Connection aborted.', timeout('The write operation timed out',))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "pyptupMultiple2.py", line 93, in <module>
backup()
File "pyptupMultiple2.py", line 43, in backup
mode=WriteMode('overwrite'))
File "/home/sakib/.local/lib/python3.6/site-packages/dropbox/base.py", line 2207, in files_upload
f,
File "/home/sakib/.local/lib/python3.6/site-packages/dropbox/dropbox.py", line 274, in request
timeout=timeout)
File "/home/sakib/.local/lib/python3.6/site-packages/dropbox/dropbox.py", line 365, in request_json_string_with_retry
timeout=timeout)
File "/home/sakib/.local/lib/python3.6/site-packages/dropbox/dropbox.py", line 449, in request_json_string
timeout=timeout,
File "/home/sakib/.local/lib/python3.6/site-packages/requests/sessions.py", line 559, in post
return self.request('POST', url, data=data, json=json, **kwargs)
File "/home/sakib/.local/lib/python3.6/site-packages/requests/sessions.py", line 512, in request
resp = self.send(prep, **send_kwargs)
File "/home/sakib/.local/lib/python3.6/site-packages/requests/sessions.py", line 622, in send
r = adapter.send(request, **kwargs)
File "/home/sakib/.local/lib/python3.6/site-packages/requests/adapters.py", line 495, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', timeout('The write operation timed out',)

The Zip file is just 93 MB and so doesn't exceed the 150 MB limit. So what should I do here?

 

I'm pretty much a noob programmer, and this is the first time I'm working with API, so any help is much much appreciated...

 

Best regards,

Sakib

 

  • Thanks for the report! This appears to be an issue when using the Dropbox Python SDK with Python 3. We're looking into it.

     

    As a workaround, please try setting an unlimited timeout when constructing your Dropbox client, like this:

    dropbox.Dropbox(TOKEN, timeout=None)

    Please let me know if that does or doesn't help.

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    Thanks for the report! This appears to be an issue when using the Dropbox Python SDK with Python 3. We're looking into it.

     

    As a workaround, please try setting an unlimited timeout when constructing your Dropbox client, like this:

    dropbox.Dropbox(TOKEN, timeout=None)

    Please let me know if that does or doesn't help.

    • Apollonius's avatar
      Apollonius
      Explorer | Level 4
      Thanks, that did the trick...
      But my script took 7 mins and 1.372 seconds. I guess that's to be expected given that the zip file is around 90 MB and I have a 250 kilobyte per sec broadband connection...
      I'm curious though, is it because of Python 3 that larger files get "timed out" errors by default and I have to erase that limit by using timeout=None?
      • Greg-DB's avatar
        Greg-DB
        Icon for Dropbox Staff rankDropbox Staff
        Great, thanks for confirming that.

        Yes, between Python 2 and Python 3 there appears to be a change in behavior that results in this issue when using a non-None timeout. We're looking into it, but for now that workaround is required to avoid this issue.

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.5,963 PostsLatest Activity: 4 hours ago
356 Following

If you need more help you can view your support options (expected response time for an email or 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!