Error using OAuth2 to connect to dropbox in Python

这一生的挚爱 提交于 2020-01-06 01:33:11

问题


On my Raspberry Pi running raspbian jessie I tried to go through the OAuth2 flow to connect a program to my dropbox using the dropbox SDK for Python which I installed via pip.

For a test, I copied the code from the documentation (and defined the app-key and secret, of course):

from dropbox import DropboxOAuth2FlowNoRedirect

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 = raw_input("Enter the authorization code here: ").strip()

try:
    access_token, user_id = auth_flow.finish(auth_code)
except Exception, e:
    print('Error: %s' % (e,))
    return

dbx = Dropbox(access_token)

I was able to get the URL and to click allow. When I then entered the authorization code however, it printed the following error:

Error: 'str' object has no attribute 'copy'

Using format_exc from the traceback-module, I got the following information:

Traceback (most recent call last):
  File "test.py", line 18, in <module>
    access_token, user_id = auth_flow.finish(auth_code)
  File "/usr/local/lib/python2.7/dist-packages/dropbox/oauth.py", line 180, in finish
    return self._finish(code, None)
  File "/usr/local/lib/python2.7/dist-packages/dropbox/oauth.py", line 50, in _finish
    url = self.build_url(Dropbox.HOST_API, '/oauth2/token')
  File "/usr/local/lib/python2.7/dist-packages/dropbox/oauth.py", line 111, in build_url
    return "https://%s%s" % (self._host, self.build_path(target, params))
  File "/usr/local/lib/python2.7/dist-packages/dropbox/oauth.py", line 89, in build_path
    params = params.copy()
AttributeError: 'str' object has no attribute 'copy'

It seems the build_path method expects a dict 'params' and receives a string instead. Any ideas?


回答1:


Thanks to smarx for his comment. The error is a known issue and will be fixed in version 3.42 of the SDK. source



来源:https://stackoverflow.com/questions/33843613/error-using-oauth2-to-connect-to-dropbox-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!