【问题标题】:Using OAuth with Google thru the Python library requests-oauthlib throws the exception MissingCodeError通过 Python 库 requests-oauthlib 将 OAuth 与 Google 一起使用会引发异常 MissingCodeError
【发布时间】:2014-02-06 00:33:45
【问题描述】:

我正在使用 Python 库 requests-oauthlib 来创建一个可以与一些主要提供商(Google、Dropbox、Facebook、Twitter)一起使用 OAuth 的应用程序。
here 提供的示例代码给了我一个例外:

raise MissingCodeError("Missing code parameter in response.")
oauthlib.oauth2.rfc6749.errors.MissingCodeError: Missing code parameter in response.

问题不在于我使用 Google API 控制台创建的 Web 应用程序客户端,因为我编写了另一段代码做同样的事情,但使用 Python 库 google-api-python-client 并且它可以工作。

有什么想法吗?

【问题讨论】:

    标签: python oauth google-oauth python-requests


    【解决方案1】:

    我的错!

    我很困惑,因为使用:

    google.fetch_token(token_url, client_secret=client_secret, authorization_response=redirect_response)
    

    redirect_response 必须是完整的 url。 使用时:

    google.fetch_token(token_url, client_secret=client_secret,
    ... code=redirect_response)
    

    redirect_response 必须是谷歌回复的代码。

    【讨论】:

    • 我实际上遇到了同样的错误......你能分享你的解决方案吗?这是我遵循的示例:requests-oauthlib.readthedocs.org/en/latest/examples/…
    • 那是很久以前的事了,我不记得所有细节了。但我猜redirect_response 类似于http://googlewhatever.../?code=mycode。如果redirect_response='http://googlewhatever.../?code=mycode',答案中编写的第一段代码将起作用。如果redirect_response='mycode',第二段代码将起作用
    • 感谢您的回复。您最终使用了哪个 OAUTH 库?
    • 我使用了 requests-oauthlib。而对于另一个 Django 项目,我使用了 django-allauth。
    猜你喜欢
    • 2018-11-24
    • 2018-06-01
    • 1970-01-01
    • 2019-01-11
    • 2015-01-01
    • 1970-01-01
    • 2020-01-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多