Code: unknown, Error: Invalid response while obtaining request token from "api.twitter.com" - how to obtain and print Twitter error message
Code: unknown, Error: Invalid response while obtaining request token from "api.twitter.com" - how to obtain and print Twitter error message
我正在使用 Django Allauth 与 Django 2.0.8 和 3.5
我已按照使用 Twitter 登录网站的说明进行操作。但是,当我尝试登录我的网站时,收到以下消息:
Social Network Login Failure
An error occurred while attempting to login via your social network account.
没有包含更多信息的日志输出 - 这给调试带来了不必要的困难。基于对此 的回答,我已将信息添加到我的模板中,它提供了更多信息:
Code: {{ auth_error.code }}, Error: {{ auth_error.exception }}
然而,错误信息是:
Code: unknown, Error: Invalid response while obtaining request token from "api.twitter.com"
这没什么帮助。我想查看 twitter.api 返回的实际响应,这样我就可以找到问题的根源 - 但是,如何输出或记录 ACTUAL[=28 对我来说并不明显=] 从推特上获得的回复 API.
当我尝试使用 django-allauth 登录时,如何 see/capture Twitter API 响应?
检查 django-allauth 代码,我可以找到给您以下错误的逻辑。 Error Code
if response.status_code not in [200, 201]:
raise OAuthError(
_('Invalid response while obtaining request token'
' from "%s".') % get_token_prefix(
self.request_token_url))
这表明如果响应代码不成功,即 200 或 201,则会引发此异常。所以你可以看到它在没有做很多记录响应的情况下引发错误。
可能还有其他方法来记录响应,但这需要库维护者或探索过整个库的人的帮助。
现在回到您的问题,您如何记录此响应。我看到的最简单的方法是编辑服务器中的本地文件 socialaccount/providers/oauth/client.py
并放置一个记录器。新文件 socialaccount/providers/oauth/client.py
看起来像这样:
import logging
LOG_FILENAME = "django_allauth_response.log"
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
handler = RotatingFileHandler(LOG_FILENAME, maxBytes=20000000, backupCount=2)
formatter = logging.Formatter('%(levelname)s: %(asctime)s %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
.........
.........
same code as in allauth/socialaccount/providers/oauth/client.py
.........
logger.info("Response of authentication:" + str(response)) #add this line
if response.status_code not in [200, 201]:
raise OAuthError(
_('Invalid response while obtaining request token'
' from "%s".') % get_token_prefix(
self.request_token_url))
一旦您在服务器中 运行 之后,您就可以打开 django_allauth_response.log
文件并检查响应。
P.S. 设置记录器可能需要进行一些小的调整,而且大多数情况下,您必须在响应的字符串转换上做更多的工作。
我在 Twitter 上遇到过两次这个问题,两次都是回调问题 URL。有一次我没有把尾随 / 放在最后。下一次,我使用了一个回调 URL,它使用了 www.一开始,但正在从不同的子域访问该站点。
此外,我按照之前发帖人的建议做了,并在 AllAuth 中修改了文件 client.py,但我发现我可以通过
将错误输出到网络上
raise OAuthError(
_('Invalid response while obtaining request token'
' from "%s". (' + str(response.status_code) + ') and (' + str(response.text) + ')')
% get_token_prefix(
self.request_token_url))
我正在使用 Django Allauth 与 Django 2.0.8 和 3.5
我已按照使用 Twitter 登录网站的说明进行操作。但是,当我尝试登录我的网站时,收到以下消息:
Social Network Login Failure
An error occurred while attempting to login via your social network account.
没有包含更多信息的日志输出 - 这给调试带来了不必要的困难。基于对此
Code: {{ auth_error.code }}, Error: {{ auth_error.exception }}
然而,错误信息是:
Code: unknown, Error: Invalid response while obtaining request token from "api.twitter.com"
这没什么帮助。我想查看 twitter.api 返回的实际响应,这样我就可以找到问题的根源 - 但是,如何输出或记录 ACTUAL[=28 对我来说并不明显=] 从推特上获得的回复 API.
当我尝试使用 django-allauth 登录时,如何 see/capture Twitter API 响应?
检查 django-allauth 代码,我可以找到给您以下错误的逻辑。 Error Code
if response.status_code not in [200, 201]:
raise OAuthError(
_('Invalid response while obtaining request token'
' from "%s".') % get_token_prefix(
self.request_token_url))
这表明如果响应代码不成功,即 200 或 201,则会引发此异常。所以你可以看到它在没有做很多记录响应的情况下引发错误。
可能还有其他方法来记录响应,但这需要库维护者或探索过整个库的人的帮助。
现在回到您的问题,您如何记录此响应。我看到的最简单的方法是编辑服务器中的本地文件 socialaccount/providers/oauth/client.py
并放置一个记录器。新文件 socialaccount/providers/oauth/client.py
看起来像这样:
import logging
LOG_FILENAME = "django_allauth_response.log"
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
handler = RotatingFileHandler(LOG_FILENAME, maxBytes=20000000, backupCount=2)
formatter = logging.Formatter('%(levelname)s: %(asctime)s %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
.........
.........
same code as in allauth/socialaccount/providers/oauth/client.py
.........
logger.info("Response of authentication:" + str(response)) #add this line
if response.status_code not in [200, 201]:
raise OAuthError(
_('Invalid response while obtaining request token'
' from "%s".') % get_token_prefix(
self.request_token_url))
一旦您在服务器中 运行 之后,您就可以打开 django_allauth_response.log
文件并检查响应。
P.S. 设置记录器可能需要进行一些小的调整,而且大多数情况下,您必须在响应的字符串转换上做更多的工作。
我在 Twitter 上遇到过两次这个问题,两次都是回调问题 URL。有一次我没有把尾随 / 放在最后。下一次,我使用了一个回调 URL,它使用了 www.一开始,但正在从不同的子域访问该站点。
此外,我按照之前发帖人的建议做了,并在 AllAuth 中修改了文件 client.py,但我发现我可以通过
将错误输出到网络上 raise OAuthError(
_('Invalid response while obtaining request token'
' from "%s". (' + str(response.status_code) + ') and (' + str(response.text) + ')')
% get_token_prefix(
self.request_token_url))