gpt4 book ai didi

python - 证书验证失败的谷歌 API

转载 作者:太空宇宙 更新时间:2023-11-03 13:32:23 26 4
gpt4 key购买 nike

我在 python 3.6 上使用 google calendar api。由于认证验证失败,我进行的任何 API 调用都失败了。我的服务帐户正常有效。我启动该类的一个实例,然后调用 get_calendar_list 方法。

代码是:

from .auth_service import get_credentials
from google.auth.transport.requests import AuthorizedSession
import json


class CalendarService:
def __init__(self, calendar_id=''):
self.credentials = get_credentials()
self.authed_session = AuthorizedSession(self.credentials)
self.service_base_url = 'https://www.googleapis.com/calendar/v3/users/me/calendarList'
self.calendar_id = calendar_id

def get_service_url(self):
return('{base_url}/{calendar_id}'.format(
base_url=self.service_base_url,
calendar_id=self.calendar_id))

def get_calendar(self):
response = self.authed_session.get(self.get_service_url())
calendar = response.json()
return calendar

def get_calendar_list(self):
response = self.authed_session.get(self.service_base_url)
calendar_list = response.json()
return calendar_list

pip freeze 的输出

aniso8601==3.0.0
cachetools==2.1.0
certifi==2018.4.16
chardet==3.0.4
click==6.7
Flask==1.0.2
Flask-Cors==3.0.4
Flask-HTTPAuth==3.2.3
Flask-RESTful==0.3.6
google-auth==1.4.1
idna==2.6
itsdangerous==0.24
Jinja2==2.10
MarkupSafe==1.0
pyasn1==0.4.2
pyasn1-modules==0.2.1
pytz==2018.4
requests==2.18.4
rsa==3.4.2
six==1.11.0
urllib3==1.22
Werkzeug==0.14.1

错误是:

C:\Workspace\Techroom\venvs\lazyhour\lazyhour\Scripts\python.exe C:/Workspace/Techroom/lazyhour-server/main.py
* Serving Flask app "main" (lazy loading)
* Environment: development
* Debug mode: on
* Restarting with stat
* Debugger is active!
* Debugger PIN: 279-826-945
* Running on http://localhost:5000/ (Press CTRL+C to quit)
C:\Workspace\Techroom\lazyhour-server\util\service_account.json
127.0.0.1 - - [22/May/2018 15:22:56] "GET /calendar/list HTTP/1.1" 500 -
Traceback (most recent call last):
File "C:\Workspace\Techroom\venvs\lazyhour\lazyhour\lib\site-packages\flask\app.py", line 2309, in __call__
return self.wsgi_app(environ, start_response)
File "C:\Workspace\Techroom\venvs\lazyhour\lazyhour\lib\site-packages\flask\app.py", line 2295, in wsgi_app
response = self.handle_exception(e)
File "C:\Workspace\Techroom\venvs\lazyhour\lazyhour\lib\site-packages\flask_cors\extension.py", line 161, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "C:\Workspace\Techroom\venvs\lazyhour\lazyhour\lib\site-packages\flask_restful\__init__.py", line 273, in error_router
return original_handler(e)
File "C:\Workspace\Techroom\venvs\lazyhour\lazyhour\lib\site-packages\flask\app.py", line 1741, in handle_exception
reraise(exc_type, exc_value, tb)
File "C:\Workspace\Techroom\venvs\lazyhour\lazyhour\lib\site-packages\flask\_compat.py", line 34, in reraise
raise value.with_traceback(tb)
File "C:\Workspace\Techroom\venvs\lazyhour\lazyhour\lib\site-packages\flask\app.py", line 2292, in wsgi_app
response = self.full_dispatch_request()
File "C:\Workspace\Techroom\venvs\lazyhour\lazyhour\lib\site-packages\flask\app.py", line 1815, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Workspace\Techroom\venvs\lazyhour\lazyhour\lib\site-packages\flask_cors\extension.py", line 161, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "C:\Workspace\Techroom\venvs\lazyhour\lazyhour\lib\site-packages\flask_restful\__init__.py", line 273, in error_router
return original_handler(e)
File "C:\Workspace\Techroom\venvs\lazyhour\lazyhour\lib\site-packages\flask\app.py", line 1718, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\Workspace\Techroom\venvs\lazyhour\lazyhour\lib\site-packages\flask\_compat.py", line 34, in reraise
raise value.with_traceback(tb)
File "C:\Workspace\Techroom\venvs\lazyhour\lazyhour\lib\site-packages\flask\app.py", line 1813, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Workspace\Techroom\venvs\lazyhour\lazyhour\lib\site-packages\flask\app.py", line 1799, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "C:\Workspace\Techroom\venvs\lazyhour\lazyhour\lib\site-packages\flask_restful\__init__.py", line 480, in wrapper
resp = resource(*args, **kwargs)
File "C:\Workspace\Techroom\venvs\lazyhour\lazyhour\lib\site-packages\flask\views.py", line 88, in view
return self.dispatch_request(*args, **kwargs)
File "C:\Workspace\Techroom\venvs\lazyhour\lazyhour\lib\site-packages\flask_restful\__init__.py", line 595, in dispatch_request
resp = meth(*args, **kwargs)
File "C:\Workspace\Techroom\venvs\lazyhour\lazyhour\lib\site-packages\flask_httpauth.py", line 93, in decorated
return f(*args, **kwargs)
File "C:\Workspace\Techroom\lazyhour-server\main.py", line 45, in get
return calendar_service.get_calendar_list()
File "C:\Workspace\Techroom\lazyhour-server\util\calendar_service.py", line 25, in get_calendar_list
response = self.authed_session.get(self.service_base_url)
File "C:\Workspace\Techroom\venvs\lazyhour\lazyhour\lib\site-packages\requests\sessions.py", line 521, in get
return self.request('GET', url, **kwargs)
File "C:\Workspace\Techroom\venvs\lazyhour\lazyhour\lib\site-packages\google\auth\transport\requests.py", line 198, in request
self._auth_request, method, url, request_headers)
File "C:\Workspace\Techroom\venvs\lazyhour\lazyhour\lib\site-packages\google\auth\credentials.py", line 121, in before_request
self.refresh(request)
File "C:\Workspace\Techroom\venvs\lazyhour\lazyhour\lib\site-packages\google\oauth2\service_account.py", line 322, in refresh
request, self._token_uri, assertion)
File "C:\Workspace\Techroom\venvs\lazyhour\lazyhour\lib\site-packages\google\oauth2\_client.py", line 145, in jwt_grant
response_data = _token_endpoint_request(request, token_uri, body)
File "C:\Workspace\Techroom\venvs\lazyhour\lazyhour\lib\site-packages\google\oauth2\_client.py", line 106, in _token_endpoint_request
method='POST', url=token_uri, headers=headers, body=body)
File "C:\Workspace\Techroom\venvs\lazyhour\lazyhour\lib\site-packages\google\auth\transport\requests.py", line 124, in __call__
six.raise_from(new_exc, caught_exc)
File "<string>", line 3, in raise_from
# Permission is hereby granted, free of charge, to any person obtaining a copy
google.auth.exceptions.TransportError: HTTPSConnectionPool(host='accounts.google.com', port=443): Max retries exceeded with url: /o/oauth2/token (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)'),))

最佳答案

首先,您介意在安装了当前密码学副本的情况下尝试此操作吗?然后,我们将要验证通过 google 的身份验证方法将哪种授权 header 传递给请求。

顺便说一句,您使用的机器是否可能具有自定义证书包(即公司或第三方管理的机器)?或者您是否在任何可能进行流量分析的防火墙后面?

关于python - 证书验证失败的谷歌 API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50469027/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com