【发布时间】:2020-06-27 16:48:10
【问题描述】:
我正在使用 python-social-auth,当我尝试刷新我的 Google Oauth2 访问令牌时,我收到以下错误:
[2017-02-15 14:41:00,089: ERROR/MainProcess] Task tasks.tasks.test_login[169e5810-489d-4134-af8f-db3b80629fd2] raised unexpected: HTTPError(u'400 Client Error: Bad Request for url: https://accounts.google.com/o/oauth2/token',)
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/celery/app/trace.py", line 240, in trace_task
R = retval = fun(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/celery/app/trace.py", line 438, in __protected_call__
return self.run(*args, **kwargs)
File "/home/paulozullu/dev/workspaces/wopik/wopik/tasks/tasks.py", line 1928, in test_login
social.refresh_token(strategy)
File "/usr/local/lib/python2.7/dist-packages/social/storage/base.py", line 54, in refresh_token
response = backend.refresh_token(token, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/social/backends/oauth.py", line 418, in refresh_token
request = self.request(url, **request_args)
File "/usr/local/lib/python2.7/dist-packages/social/backends/base.py", line 225, in request
response.raise_for_status()
File "/usr/local/lib/python2.7/dist-packages/requests/models.py", line 909, in raise_for_status
raise HTTPError(http_error_msg, response=self)
HTTPError: 400 Client Error: Bad Request for url: https://accounts.google.com/o/oauth2/token
我使用以下代码刷新访问令牌:
from social.apps.django_app.utils import load_strategy
w_user = WUser.objects.get(auth_user=A('username','xxxx'))
social = UserSocialAuth.objects.get(user_id=w_user.auth_user.id)
strategy = load_strategy()
social.refresh_token(strategy)
我是不是做错了什么?
【问题讨论】:
-
你有没有找到解决这个问题的方法?有同样的问题。
-
不幸的是,没有。我正在手动实现 Youtube 登录
-
我遇到了同样的问题,还没有找到解决办法。但我想我知道原因。这可能是因为您的 social_user.extra_data 没有刷新令牌。我相信如果您可以登录以进行离线访问,您可以获得 access_token 并刷新令牌,就像您在这里可以做到的那样:developers.google.com/oauthplayground。但就我而言,没有刷新令牌。
-
这方面有什么更新吗?同样的问题
标签: google-oauth python-social-auth