Google Plus API中的httplib2证书主机名不匹配
我尝试使用Google Plus的API来进行OAuth2的流程。
我得到了验证信息,准备去换取访问令牌,但这时出现了错误。
httplib2.CertificateHostnameMismatch:
Server presented certificate that does not match host accounts.google.com:
服务器提供的证书和主机www.googleapis.com不匹配。
提供的证书(通用名称)是*.g.doubleclick.net。
为什么它们会不一样呢?
我的代码是这样的:
from oauth2client.client import flow_from_clientsecrets
CLIENT_SECRETS = 'client_secrets.json'
MISSING_CLIENT_SECRETS_MESSAGE = ""
FLOW = flow_from_clientsecrets(CLIENT_SECRETS,
scope='https://www.googleapis.com/auth/plus.me',
message=MISSING_CLIENT_SECRETS_MESSAGE)
FLOW.step1_get_authorize_url()
# the url is outputted and
# my browser forward to it to get the verifier
FLOW.step2_exchange(verifier)
# I paste the verifier and execute this line, then error occurred.
有没有什么提示呢?
附注:我的urllib2
版本是0.7.2。
1 个回答
1
如果你碰巧遇到这个问题,可能是因为出现了证书主机名不匹配的错误,我建议你先检查一下你正在使用的Python版本(可以在命令行输入python --version
来查看)。
我之前用的是Python 2.7.2,结果发现这个版本在处理SSL证书时有一些已知的问题。我把它升级到了2.7系列的最新版本,结果证书主机名不匹配的错误就消失了。