每次凭证= storage.get()都返回None

时间:2014-09-11 12:03:15

标签: python django google-app-engine

storage = Storage(CredentialsModel, 'id', request.user, 'credential')
credential = storage.get()
if credential is None or credential.invalid == True:
    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("storage", "v1", http=http)
    req = service.objects().copy(
        sourceBucket="template1",
        sourceObject="index.html",
        destinationBucket="jatin1",
        destinationObject="index1.html",
        body = {}
        )
    resp = req.execute()

我正在使用django gae app。我正在尝试使用谷歌云存储API。但是storage.get()每次都返回无。我检查了数据库。生成CredentialsModel表,并且凭证字段也有数据。虽然凭证= storage.get()返回None,但如果条件除了else,则进入。

这里是生成凭证的函数,并将其保存在CredentialsModel表中。

def auth_return(request):
  if not xsrfutil.validate_token(settings.SECRET_KEY, request.REQUEST['state'],
                                 request.user):
    return  HttpResponseBadRequest()
  credential = FLOW.step2_exchange(request.REQUEST)
  storage = Storage(CredentialsModel, 'id', request.user, 'credential')
  log.info("during auth return>>>>>>>>>>>>>>>>>>>>>>>>>>>"+str(credential))
  storage.put(credential)
  print "this is the storage", storage
  return HttpResponseRedirect("/dashboard/")

0 个答案:

没有答案