We are aware of the issue with the badge emails resending to everyone, we apologise for the inconvenience - learn more here.
Forum Discussion
masonml
5 months agoNew member | Level 2
Refresh Token for Python Project
Hi all,
I'm unfamiliar with APIs and this is my first project of this type so any help is appreciated. I've written a python code that uploads an image from a camera to my Dropbox app. The code works fine, but I'm struggling with the OAuth portion as I need a permanent access code since I will be away from the code/computer while the code is running.
I ran the code below with my app keys:
import dropbox
from dropbox import DropboxOAuth2FlowNoRedirect
'''
This example walks through a basic oauth flow using the existing long-lived token type
Populate your app key and app secret in order to run this locally
'''
APP_KEY = ""
APP_SECRET = ""
auth_flow = DropboxOAuth2FlowNoRedirect(APP_KEY, APP_SECRET)
authorize_url = auth_flow.start()
print("1. Go to: " + authorize_url)
print("2. Click \"Allow\" (you might have to log in first).")
print("3. Copy the authorization code.")
auth_code = input("Enter the authorization code here: ").strip()
try:
oauth_result = auth_flow.finish(auth_code)
except Exception as e:
print('Error: %s' % (e,))
exit(1)
with dropbox.Dropbox(oauth2_access_token=oauth_result.access_token) as dbx:
dbx.users_get_current_account()
print("Successfully set up client!")
The client was successfully set up after I entered the key from my browser, but no refresh token appeared on Dropbox. I attempted again on a different computer (I was testing the code on my laptop, which is not the computer that will be running the code, and received this error:
Error: HTTPSConnectionPool(host='api.dropboxapi.com', port=443): Max retries exceeded with url: /oauth2/token (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1129)')))
Is this because I already set up the client on my laptop, or a separate error altogether? How can I fix it?
- Greg-DBDropbox Staff
Dropbox is no longer offering the option for creating new long-lived access tokens. Dropbox is now issuing short-lived access tokens (and optional refresh tokens) instead of long-lived access tokens. You can find more information on this migration here.
Apps can still get long-term access by requesting "offline" access though, in which case the app receives a "refresh token" that can be used to retrieve new short-lived access tokens as needed, without further manual user intervention. Refresh tokens do not expire automatically and can be used repeatedly. You can find more information in the OAuth Guide and authorization documentation. There's a basic outline of processing this flow in this blog post which may serve as a useful example.
Also, note that you do not need to implement the refresh process yourself. The Dropbox Python SDK will handle that logic for you as long as you pass the refresh token, app key, and if needed (when not using PKCE), app secret to the Dropbox client. The code you used does not request a refresh token. Instead, for the official Dropbox Python SDK, you can find examples of how this works with refresh tokens at the following links:- https://github.com/dropbox/dropbox-sdk-python/blob/main/example/oauth/commandline-oauth-scopes.py
- https://github.com/dropbox/dropbox-sdk-python/blob/main/example/oauth/commandline-oauth-pkce.py
As for the SSL error you mentioned, that seems to indicate an issue establishing a secure connection to the Dropbox API servers from that computer. Check for anything on that computer, such as a VPN, proxy, firewall, or other security software that may be interfering with your network connection.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,877 PostsLatest Activity: 6 hours agoIf 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!