检查 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. 设置记录器可能需要一些小的调整,而且大多数情况下您需要在响应的字符串转换上做更多的工作。