使用OAuth2连接到Python中的保管箱时出错

问题描述:

在运行raspbian jessie的Raspberry Pi上,我尝试通过OAuth2流使用我通过pip安装的适用于Python的Dropbox SDK将程序连接到我的Dropbox。

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)

我能够获取URL并单击允许。但是,当我输入授权代码时,它打印了以下错误:

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'

使用traceback模块中的format_exc,我得到以下信息:

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'

似乎build_path方法期望一个dict'params'并接收一个字符串。有任何想法吗?

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

感谢 smarx 发表评论。该错误是一个已知问题,将在SDK的3.42版中修复。

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