Google oauth登录Python:"redirect_uri的无效参数值:缺少方案:无" [英] Google oauth login Python: "Invalid parameter value for redirect_uri: Missing scheme: None"

查看:127
本文介绍了Google oauth登录Python:"redirect_uri的无效参数值:缺少方案:无"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:

flow = OAuth2WebServerFlow(client_id='XXXXXX',client_secret='XXXXXXXXX',scope='https://www.googleapis.com/auth/userinfo.email',redirect_uri='https://XXXXXXXX.com/oauth2callback')
log.debug(flow.__dict__)
if not self.request.get("code"):
    auth_uri = flow.step1_get_authorize_url()
    log.debug("the link " + auth_uri)
    self.redirect(auth_uri)
else:
    code = self.request.get("code")
    log.debug("code=>"+str(code))
    credentials = flow.step2_exchange(str(code))
    http = httplib2.Http()
    http = credentials.authorize(http)
    log.info('authorisation completed')
    service = build('gmail', 'v2', http=http)
    self.render_json(service.__dict__)

所有这些之后,进行编码.我收到如下错误:

After all this, code. I am getting an error as below:

Failed to retrieve access token: {
  "error" : "invalid_request",
  "error_description" : "Invalid parameter value for redirect_uri: Missing scheme: None"
}

回溯错误:

Failed to retrieve access token: {
  "error" : "invalid_request",
  "error_description" : "Invalid parameter value for redirect_uri: Missing scheme: None"
}
E 2014-07-25 16:42:31.077
invalid_request
Traceback (most recent call last):
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1535, in __call__
    rv = self.handle_exception(request, response, e)
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1529, in __call__
    rv = self.router.dispatch(request, response)
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1278, in default_dispatcher
    return route.handler_adapter(request, response)
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1102, in __call__
    return handler.dispatch()
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 572, in dispatch
    return self.handle_exception(e, self.app.debug)
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 570, in dispatch
    return method(*args, **kwargs)
  File "/base/data/home/apps/s~syncliologinservice/googlelogin.377497220523277441/handlers/common_handler.py", line 39, in google_login
    credentials = flow.step2_exchange(str(code))
  File "/base/data/home/apps/s~syncliologinservice/googlelogin.377497220523277441/oauth2client/client.py", line 893, in step2_exchange
    raise FlowExchangeError(error_msg)
FlowExchangeError: invalid_request

任何人都可以帮助我.坚持了两天.

Can anyone help me out. Stuck for a 2 days on this.

推荐答案

这是因为您缺少重定向URI

This is because you are missing the redirect URI

在我的示例中

REDIRECT_URI = 'http://localhost:8000/app'
OAUTH2_SCOPE = 'https://www.googleapis.com/auth/drive.readonly'

flow = flow_from_clientsecrets(CLIENTSECRET_LOCATION, OAUTH2_SCOPE)
flow.redirect_uri = REDIRECT_URI
credentials = flow.step2_exchange(authorization_code)

这篇关于Google oauth登录Python:"redirect_uri的无效参数值:缺少方案:无"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆