证书验证失败 OAuth2
我正在使用下面的代码来获取一个令牌,以便访问谷歌日历的API。但我不明白为什么我总是会遇到以下错误:
[Errno 1] _ssl.c:504: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed.
错误追踪信息:
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-
packages/django/core/handlers/base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
20. return view_func(request, *args, **kwargs)
File "/Users/aribaaboobakar/djcode/newProj/books/views.py" in auth_return
67. credential = FLOW.step2_exchange(request.REQUEST)
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/google_api_python_client-1.2-py2.7.egg/oauth2client/util.py" in positional_wrapper
132. return wrapped(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/google_api_python_client-1.2-py2.7.egg/oauth2client/client.py" in step2_exchange
1283. headers=headers)
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/httplib2-0.9-py2.7.egg/httplib2/__init__.py" in request
1593. (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/httplib2-0.9-py2.7.egg/httplib2/__init__.py" in _request
1335. (response, content) = self._conn_request(conn, request_uri, method, body, headers)
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/httplib2-0.9-py2.7.egg/httplib2/__init__.py" in _conn_request
1257. conn.connect()
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/httplib2-0.9-py2.7.egg/httplib2/__init__.py" in connect
1044. raise SSLHandshakeError(e)
Exception Type: SSLHandshakeError at /oauth2callback
Exception Value: [Errno 1] _ssl.c:504: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
def index(request):
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(disable_ssl_certificate_validation=True)
http = credential.authorize(http)
service = build("plus", "v1", http=http)
activities = service.activities()
activitylist = activities.list(collection='public',
userId='me').execute()
logging.info(activitylist)
return render_to_response('plus/welcome.html', {
'activitylist': activitylist,
})
@login_required
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')
storage.put(credential)
return HttpResponseRedirect("/")
1 个回答
0
错误信息 SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
通常是因为你电脑上的 系统时间
设置不正确,或者你的 CA证书过期了,需要更新
。
请检查一下你电脑上的 时间和日期
是否正确。