在 Python 中使用 OAuth2 連接到保管箱時出錯 (Error using OAuth2 to connect to dropbox in Python)


問題描述

在 Python 中使用 OAuth2 連接到保管箱時出錯 (Error using OAuth2 to connect to dropbox in Python)

在運行 raspbian jessie 的 Raspberry Pi 上,我嘗試通過 OAuth2 流程使用我通過 pip 安裝的用於 Python 的 Dropbox SDK 將程序連接到我的 Dropbox。

為了測試,我從 documentation(當然還定義了 app‑key 和 secret):

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 並點擊允許。然而,當我輸入授權碼時,它打印了以下錯誤:

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

使用追溯模塊中的 format_exc,我得到以下信息:

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' 而是接收一個字符串。有什麼想法嗎?


參考解法

方法 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

(by Andy_CaponeAndy_Capone)

參考文件

  1. Error using OAuth2 to connect to dropbox in Python (CC BY‑SA 2.5/3.0/4.0)

#dropbox #python-2.7 #OAuth #raspberry-pi #dropbox-api






相關問題

獲取 Dropbox 共享鏈接的文件列表 (Get list of files for dropbox shared link)

將文件上傳到保管箱時,方法出錯 (while uploading a file to dropbox getting an error with method)

Dropbox Api putFile php 發送文件失敗 (Dropbox Api putFile php fail send file)

Tiếp tục quá trình tải lên trong IOS nền (Continue uploading process in background IOS)

API Dropbox: phát hiện cập nhật tệp và nhận URL đến tệp? (Dropbox API: detect file updates, and get a URL to a file?)

Mac OS X 文件的 st_flags(用戶定義的標誌)是什麼? (What are st_flags (user defined flags) for a file Mac OS X?)

Dropbox如何監控? (How does dropbox monitoring?)

如何在 Dropbox 中使用 Bazaar? (How to use Bazaar with Dropbox?)

在 Python 中使用 OAuth2 連接到保管箱時出錯 (Error using OAuth2 to connect to dropbox in Python)

從樹莓派自動上傳到保管箱? (automatic upload on dropbox from raspberry pi?)

識別 macOS 上的託管文件夾 (Identify managed folders on macOS)

我們如何在下載/上傳 dropbbox 方法中獲取文件 mime-type/content-type? (How can we get files mime-type/content-type in download/upload dropbbox methods?)







留言討論