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/12/2018年12:51:07 "GET /auth/ AnonymousUser/1.1“500 111109
我希望对gmail用户进行身份验证。
发布于 2018-12-26 09:28:40
从DjangoORMStorage的类文档中我可以看到
从Django ORM检索的oauth2client.Credentials与用于查询模型的
model、key_value->key_name对关联,以及property_name标识CredentialsProperty字段,所有这些都是在该存储对象的构造函数中定义的。
因此,您需要传递DjangoORMStorage初始化的DjangoORMStorage值,并且它不应该是一个对象。我认为你的实施应该是这样的:
def gmail_authenticate(request):
if not request.user.is_authenticated:
# Raise or Return Not authenticated response
storage = DjangoORMStorage(CredentialsModel, 'id', request.user.id, 'credential')
credential = storage.get()
# Rest of the Codehttps://stackoverflow.com/questions/53929020
复制相似问题