Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
Hi,
I'm new to this and need some help with setting up access with my Dropbox app to a Dropbox account using Python. When running the code I get the error shown below. I have inserted the app and secret codes into it. Plus the app has an API token. Any guidance would be greatly appreciated.
See python code below error message.
Traceback (most recent call last):
File "dropbox_test.py", line 2, in <module>
import dropbox
File "/Users/ninekay/Desktop/Python/dropbox.py", line 24
client = dropbox.client.DropboxClient(access_token)
import dropbox
app_key = 'qdrn1l679o14y86'
app_secret = '<redacted>'
flow = dropbox.client.DropboxOAuth2FlowNoRedirect(app_key, app_secret)
authorize_url = 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.'
code = raw_input("Enter the authorization code here: ").strip()
access_token, user_id = flow.finish(code)
client = dropbox.client.DropboxClient(access_token)
print 'linked account: ', client.account_info()
f = open('working-draft.txt', 'rb')
response = client.put_file('/magnum-opus.txt', f)
print 'uploaded: ', response
folder_metadata = client.metadata('/')
print 'metadata: ', folder_metadata
f, metadata = client.get_file_and_metadata('/magnum-opus.txt')
out = open('magnum-opus.txt', 'wb')
out.write(f.read())
out.close()
print metadata
Change the name of your Python file. When you do import dropbox
, Python is first noticing the file dropbox.py
in the current directory and trying to import that. What you want it to actually do is import the Dropbox SDK, so rename your Python file to something other than dropbox.py
, and things should work.
Thanks for the answer. we have made progress. Now when making any choice at the menu I get the following error.
Are you sure you're entering the access code from dropbox.com properly? Also make sure you're only using the code you get once.
"Are you sure you're entering the access code from dropbox.com properly"
Yes, I'm using a new access token.
1.
I go to my App console on Dropbox Developers
2.
I open up my app
3.
Then go to Generated access token.
4.
I use that token when it prompts me.
5.
I'm using the terminal on a Mac 10.11.4.
Just upgraded python from 2.7.6 to 2.7.9 and still incurring the same error message.
W8006005A54:python ninekay$ python upload.py
Go to: https://www.dropbox.com/1/oauth2/authorize?response_type=code&client_id=qdrn1l679o14y86
Click "Allow" (you might have to log in first)
Copy the authorization code.
Enter the authorization code here: <REDACTED>
Traceback (most recent call last):
File "upload.py", line 21, in <module>
access_token, user_id = flow.finish(code)
File "/Library/Python/2.7/site-packages/dropbox-2.2.0-py2.7.egg/dropbox/client.py", line 1398, in finish
return self._finish(code, None)
File "/Library/Python/2.7/site-packages/dropbox-2.2.0-py2.7.egg/dropbox/client.py", line 1265, in _finish
response = self.rest_client.POST(url, params=params)
File "/Library/Python/2.7/site-packages/dropbox-2.2.0-py2.7.egg/dropbox/rest.py", line 316, in POST
return cls.IMPL.POST(*n, **kw)
File "/Library/Python/2.7/site-packages/dropbox-2.2.0-py2.7.egg/dropbox/rest.py", line 254, in POST
post_params=params, headers=headers, raw_response=raw_response)
File "/Library/Python/2.7/site-packages/dropbox-2.2.0-py2.7.egg/dropbox/rest.py", line 227, in request
raise ErrorResponse(r, r.read())
dropbox.rest.ErrorResponse: [400] u'invalid_grant'
You're not supposed to use your generated access token there. As the app says, you should go to the URL it gives you and authorize the app. You'll then receive an access code (not access token) that you need to copy/paste back into the app.
BTW, I've redacted your access token, but you should probably unlink your app (from dropbox.com/account/security) now that your access token has been published here. With an access token, someone can read and write files in your account, so you never want to share an access token with anyone.
Steve,
Now have access. thanks a million for your help.
When running in the terminal it never displayed that message about going to the other URL.
So I ran it in my text editor and it showed up. Its the first time I used it.
Hi there!
If you need more help you can view your support options (expected response time for a 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!