【发布时间】:2018-12-26 07:45:38
【问题描述】:
def gmail_authenticate(request):
storage = DjangoORMStorage(CredentialsModel, 'id', request.user, 'credential')
credential = storage.get()
if credential is None or credential.invalid:
FLOW.params['state'] = xsrfutil.generate_token(settings.SECRET_KEY,
request.user)
authorize_url = FLOW.step1_get_authorize_url()
return HttpResponseRedirect(authorize_url)
else:
http = httplib2.Http()
http = credential.authorize(http)
service = build('gmail', 'v1', http = http)
print('access_token = ', credential.access_token)
status = True
return render(request, 'index.html', {'status': status})
我来了
TypeError: 'AnonymousUser' 对象不可迭代 在阅读凭据时
我遇到了错误。
文件“C:\Users\admin\Desktop\GmailTest\google- login\gfglogin\gfgauth\views.py",第 10 行,在 gmail_authenticate 凭证 = storage.get()
TypeError: 'AnonymousUser' 对象不可迭代 [26/Dec/2018 12:51:07]“GET /auth/HTTP/1.1”500 111109
我希望对 gmail 用户进行身份验证。
【问题讨论】:
-
什么是
xsrfutil.generate_token?我假设这是来自您正在使用的某个库,您可以链接到文档吗?从错误消息中可以看出,此方法需要一个可迭代对象作为其第二个参数传递,而 Django 用户对象不是。