HTTPError finishing the OAuth2 flow with Dropbox SDK v 3.42 for Python

僤鯓⒐⒋嵵緔 提交于 2020-01-16 13:18:06

问题


In SDK version 3.41 there was a bug that prevented the finish method of DropboxOAuth2FlowNoRedirect to actually finish. I asked about this here yesterday. After I updated to version 3.42, I get a new error. I once again took the code from the Dropbox-documentation and changed it to the following to get a traceback and to be able to execute it outside of a function:

# added traceback-import
from traceback import format_exc

from dropbox import DropboxOAuth2FlowNoRedirect

# replaced real key and secret by XXX
APP_KEY = "XXX"
APP_SECRET = "XXX"

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:
    # changed output and removed return
    print format_exc()
else:
    print user_id, access_token

Running this gives me the following output after entering the authorization code:

Traceback (most recent call last):
  File "test.py", line 16, in <module>
    access_token, user_id = auth_flow.finish(auth_code)
  File "/usr/local/lib/python2.7/dist-packages/dropbox/oauth.py", line 178, in finish
    return self._finish(code, None)
  File "/usr/local/lib/python2.7/dist-packages/dropbox/oauth.py", line 60, in _finish
    resp.raise_for_status()
  File "/usr/local/lib/python2.7/dist-packages/requests/models.py", line 837, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
HTTPError: 400 Client Error: Bad Request for url: https://www.dropbox.com/1/oauth2/token

Where could I have made a mistake? Or is it a problem with the SDK?

来源:https://stackoverflow.com/questions/33858793/httperror-finishing-the-oauth2-flow-with-dropbox-sdk-v-3-42-for-python

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