Take Your Search Game to the Next Level with Dropbox Dash 🚀✨ Curious how it works? Ask us here!
Forum Discussion
istvanzk
31 days agoHelpful | Level 6
Problem accessing Dropbox API from an embedded device
I’m using a Seeed Studio XIAO ESP32S3 board programmed with Adafruit CircuitPython 9.2.7. I have written a very lite “SDK” to be able to issue requests to Dropbox API (V2) for a limited number of operations: (re)authentication, get_user_account, list_folder, upload_file. My code is available here https://github.com/istvanzk/xiaocam_cpy
The initial OAuth2 authorization works fine. I request "offline" access during the OAuth app authorization flow on a development machine, not the XIAO board. Then I use the received "refresh token" (stored in settings.toml) to programmatically get a new short-lived access token at any point in time, without further manual user interaction, in the code running on the XIAO board.
Problem: I'm having a strange error when sending any POST request to Dropbox API (V2) host and route, e.g. to https://api.dropboxapi.com/2/users/get_current_account and with the headers set according to the https://www.dropbox.com/developers/documentation/http/documentation#users-get_current_account info. Authentication token is correct because it works after the below described ‘fix’ below.
The error "OSError: [Errno 116] ETIMEDOUT" is thrown by a socket.recv_into(result) line (from the original adafruit_requests.py implementation code) meant to check the first character/byte of the response from the server (checked to be “H”). Strangely the only way I found to 'solve' this error here was to insert a time.sleep(0.02) before each of the corresponding request data is sent with socket.send()
The observed error is described in more details in the https://github.com/istvanzk/xiaocam_cpy?tab=readme-ov-file#adafruit_requests_fix section, with additional discussions and attempts to debug it on the Adafruit_CircuitPython_Requests issue #209.
The error can be reproduced using the https://github.com/istvanzk/xiaocam_cpy/blob/main/dbx_test.py code when the original adafruit_requests module is used instead of my modified https://github.com/istvanzk/xiaocam_cpy/blob/main/adafruit_requests_fix.py.
Question #0: Is there a particular way the Dropbox API server handles the socket requests/connections? I could not find anything in particular when going through the official Dropbox API Python SDK code, but I might have missed it.
Question #1: After applying the 'fix' described above, the image file upload times are unexpectedly very large e.g., it was approx. 20 seconds for an image of 50KB. Combined with Q#0 it seems the connection is somehow rate limited but I was not able to find the reasons for this.
NOTE: I had to remove all links in this post due to the
5 Replies
Sort By
- istvanzk27 days agoHelpful | Level 6
The solution to such problems is to use a separate client Session for the Dropbox API.
In my case I used a timeout value of 60sec for Dropbox API, while for any other server a 10sec timeout is fine. - istvanzk29 days agoHelpful | Level 6
Thank you very much Heyden. I'll follow up on these.
- istvanzk29 days agoHelpful | Level 6
The 'rate limitation' observed for the image upload as mentioned in the original post Q#1 is obviously mostly due to the addition on the time.sleep(0.02) delay (which adds up to around 20 seconds in total).
However, why the socket.recv_into(...) fails to start with is still unclear to me, see Q#0. - istvanzk29 days agoHelpful | Level 6
UPDATE:
I have now done the test on a host/dev machine (Python 3.12) using the original adafruit_requests implementation and my custom Dropbox API implementation for CircuitPython. It runs as expected, no errors, no timeouts.
This means the delay 'fix' I came to use when running on the XIAO board is needed due to some Dropbox API server behaviour. Perhaps something to do with the SSL. It's more and more strange, to me at least... - istvanzk31 days agoHelpful | Level 6
NOTE: I had to remove all links in this post due to an error complaining about invalid HTML tags a, a class, etc.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.6,012 PostsLatest Activity: 2 hours ago
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
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!