twitter登录:401客户端错误:需要授权

时间:2014-09-26 20:03:03

标签: python django twitter-oauth python-social-auth

我正在使用python-social-auth在本地实现twitter登录,但我收到401客户端错误。我的django版本是1.6。

Traceback:
File "/Library/Python/2.7/site-packages/django/core/handlers/base.py" in get_response
  112.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Library/Python/2.7/site-packages/social/apps/django_app/utils.py" in wrapper
  45.             return func(request, backend, *args, **kwargs)
File "/Library/Python/2.7/site-packages/social/apps/django_app/views.py" in auth
  12.     return do_auth(request.social_strategy, redirect_name=REDIRECT_FIELD_NAME)
File "/Library/Python/2.7/site-packages/social/actions.py" in do_auth
  25.     return strategy.start()
File "/Library/Python/2.7/site-packages/social/strategies/base.py" in start
  66.             return self.redirect(self.backend.auth_url())
File "/Library/Python/2.7/site-packages/social/backends/oauth.py" in auth_url
  99.         token = self.set_unauthorized_token()
File "/Library/Python/2.7/site-packages/social/backends/oauth.py" in set_unauthorized_token
  158.         token = self.unauthorized_token()
File "/Library/Python/2.7/site-packages/social/backends/oauth.py" in unauthorized_token
  177.                                 method=self.REQUEST_TOKEN_METHOD)
File "/Library/Python/2.7/site-packages/social/backends/base.py" in request
  205.         response.raise_for_status()
File "/Library/Python/2.7/site-packages/requests/models.py" in raise_for_status
  808.             raise HTTPError(http_error_msg, response=self)

Exception Type: HTTPError at /login/twitter/
Exception Value: 401 Client Error: Authorization Required

documentation中它建议安装ntp.I不知道如何安装ntp。

2 个答案:

答案 0 :(得分:6)

事实证明我在twitter app控制台中将回调网址字段留空了。虽然,它不是必需的,但是放http://127.0.0.1:8000/complete/twitter/(注意末尾的斜线)可以完成这项工作。

答案 1 :(得分:2)

另请注意,如果您将最后的“/”留在回拨网址的末尾,则会出现此错误。它应该读

http://127.0.0.1:8000/complete/twitter/