在公司代理后面使用Python访问Google工作表失败,SSL:证书\u验证\u失败
我们试图从公司代理后面的Linux服务器读取Google工作表的内容。通常,我们可以通过代理连接到Internet,例如pip安装或python请求可以正常工作。但以下情况并非如此:在公司代理后面使用Python访问Google工作表失败,SSL:证书\u验证\u失败,python,ssl,google-sheets,google-sheets-api,Python,Ssl,Google Sheets,Google Sheets Api,我们试图从公司代理后面的Linux服务器读取Google工作表的内容。通常,我们可以通过代理连接到Internet,例如pip安装或python请求可以正常工作。但以下情况并非如此: export GOOGLE_APPLICATION_CREDENTIALS="path to our credentials file" python 错误: Traceback (most recent call last): File "<stdin>", line 1, in <mod
export GOOGLE_APPLICATION_CREDENTIALS="path to our credentials file"
python
错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.6/site-packages/googleapiclient/_helpers.py", line 130, in positional_wrapper
return wrapped(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/googleapiclient/http.py", line 851, in execute
method=str(self.method), body=self.body, headers=self.headers)
File "/usr/local/lib/python3.6/site-packages/googleapiclient/http.py", line 184, in _retry_request
raise exception
File "/usr/local/lib/python3.6/site-packages/googleapiclient/http.py", line 165, in _retry_request
resp, content = http.request(uri, method, *args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/google_auth_httplib2.py", line 187, in request
self._request, method, uri, request_headers)
File "/usr/local/lib/python3.6/site-packages/google/auth/credentials.py", line 122, in before_request
self.refresh(request)
File "/usr/local/lib/python3.6/site-packages/google/oauth2/service_account.py", line 322, in refresh
request, self._token_uri, assertion)
File "/usr/local/lib/python3.6/site-packages/google/oauth2/_client.py", line 145, in jwt_grant
response_data = _token_endpoint_request(request, token_uri, body)
File "/usr/local/lib/python3.6/site-packages/google/oauth2/_client.py", line 106, in _token_endpoint_request
method='POST', url=token_uri, headers=headers, body=body)
File "/usr/local/lib/python3.6/site-packages/google_auth_httplib2.py", line 116, in __call__
url, method=method, body=body, headers=headers, **kwargs)
File "/usr/local/lib/python3.6/site-packages/httplib2/__init__.py", line 1957, in request
cachekey,
File "/usr/local/lib/python3.6/site-packages/httplib2/__init__.py", line 1622, in _request
conn, request_uri, method, body, headers
File "/usr/local/lib/python3.6/site-packages/httplib2/__init__.py", line 1528, in _conn_request
conn.connect()
File "/usr/local/lib/python3.6/site-packages/httplib2/__init__.py", line 1311, in connect
self.sock = self._context.wrap_socket(sock, server_hostname=self.host)
File "/usr/local/lib/python3.6/ssl.py", line 407, in wrap_socket
_context=self, _session=session)
File "/usr/local/lib/python3.6/ssl.py", line 817, in __init__
self.do_handshake()
File "/usr/local/lib/python3.6/ssl.py", line 1077, in do_handshake
self._sslobj.do_handshake()
File "/usr/local/lib/python3.6/ssl.py", line 689, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
位置包装中的文件“/usr/local/lib/python3.6/site packages/googleapiclient/_helpers.py”,第130行
已包装退货(*args,**kwargs)
文件“/usr/local/lib/python3.6/site packages/googleapiclient/http.py”,执行中的第851行
method=str(self.method),body=self.body,headers=self.headers)
文件“/usr/local/lib/python3.6/site packages/googleapiclient/http.py”,第184行,在重试请求中
引发异常
文件“/usr/local/lib/python3.6/site packages/googleapiclient/http.py”,第165行,在重试请求中
resp,content=http.request(uri,方法,*args,**kwargs)
文件“/usr/local/lib/python3.6/site packages/google_auth_httplib2.py”,请求中的第187行
self.\u请求、方法、uri、请求头)
文件“/usr/local/lib/python3.6/site packages/google/auth/credentials.py”,第122行,在请求之前
自我刷新(请求)
刷新中的文件“/usr/local/lib/python3.6/site packages/google/oauth2/service_account.py”,第322行
请求,self.\u令牌\u uri,断言)
jwt_grant中的文件“/usr/local/lib/python3.6/site packages/google/oauth2/_client.py”,第145行
响应\数据=\令牌\端点\请求(请求,令牌\ uri,正文)
文件“/usr/local/lib/python3.6/site packages/google/oauth2/_client.py”,第106行,在令牌端点请求中
方法='POST',url=token\u uri,headers=headers,body=body)
文件“/usr/local/lib/python3.6/site packages/google_auth_httplib2.py”,第116行,在调用中__
url,method=method,body=body,headers=headers,**kwargs)
文件“/usr/local/lib/python3.6/site packages/httplib2/_init__.py”,第1957行,在请求中
cachekey,
文件“/usr/local/lib/python3.6/site packages/httplib2/_init__.py”,第1622行,在请求中
conn,请求uri,方法,正文,头
文件“/usr/local/lib/python3.6/site packages/httplib2/_init__.py”,第1528行,在连接请求中
连接
文件“/usr/local/lib/python3.6/site packages/httplib2/_init__.py”,第1311行,在connect中
self.sock=self.\u context.wrap\u套接字(sock,server\u hostname=self.host)
文件“/usr/local/lib/python3.6/ssl.py”,第407行,在wrap_套接字中
_上下文=自身,_会话=会话)
文件“/usr/local/lib/python3.6/ssl.py”,第817行,在__
self.do_握手
文件“/usr/local/lib/python3.6/ssl.py”,第1077行,在do_握手中
赛尔夫:握手
文件“/usr/local/lib/python3.6/ssl.py”,第689行,在do_握手中
赛尔夫:握手
ssl.SSLError:[ssl:CERTIFICATE\u VERIFY\u FAILED]证书验证失败(\u ssl.c:852)
我们如何解决这个问题
我们已经检查过的内容:
- 当我们不支持公司代理时,代码和凭据可以工作
- 系统时钟正常
- 在代理之后,我们可以使用curl连接到相关URL(和),而不会出错
curl-X POSThttps://oauth2.googleapis.com/token
检查并确保代理服务器已设置为接受SSL证书。这可能是一个非常广泛的问题,在没有客户机和服务器信息的情况下进行调试,我只能推测可能是什么问题。我认为在这种情况下,最好与公司代理的管理员交谈。
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.6/site-packages/googleapiclient/_helpers.py", line 130, in positional_wrapper
return wrapped(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/googleapiclient/http.py", line 851, in execute
method=str(self.method), body=self.body, headers=self.headers)
File "/usr/local/lib/python3.6/site-packages/googleapiclient/http.py", line 184, in _retry_request
raise exception
File "/usr/local/lib/python3.6/site-packages/googleapiclient/http.py", line 165, in _retry_request
resp, content = http.request(uri, method, *args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/google_auth_httplib2.py", line 187, in request
self._request, method, uri, request_headers)
File "/usr/local/lib/python3.6/site-packages/google/auth/credentials.py", line 122, in before_request
self.refresh(request)
File "/usr/local/lib/python3.6/site-packages/google/oauth2/service_account.py", line 322, in refresh
request, self._token_uri, assertion)
File "/usr/local/lib/python3.6/site-packages/google/oauth2/_client.py", line 145, in jwt_grant
response_data = _token_endpoint_request(request, token_uri, body)
File "/usr/local/lib/python3.6/site-packages/google/oauth2/_client.py", line 106, in _token_endpoint_request
method='POST', url=token_uri, headers=headers, body=body)
File "/usr/local/lib/python3.6/site-packages/google_auth_httplib2.py", line 116, in __call__
url, method=method, body=body, headers=headers, **kwargs)
File "/usr/local/lib/python3.6/site-packages/httplib2/__init__.py", line 1957, in request
cachekey,
File "/usr/local/lib/python3.6/site-packages/httplib2/__init__.py", line 1622, in _request
conn, request_uri, method, body, headers
File "/usr/local/lib/python3.6/site-packages/httplib2/__init__.py", line 1528, in _conn_request
conn.connect()
File "/usr/local/lib/python3.6/site-packages/httplib2/__init__.py", line 1311, in connect
self.sock = self._context.wrap_socket(sock, server_hostname=self.host)
File "/usr/local/lib/python3.6/ssl.py", line 407, in wrap_socket
_context=self, _session=session)
File "/usr/local/lib/python3.6/ssl.py", line 817, in __init__
self.do_handshake()
File "/usr/local/lib/python3.6/ssl.py", line 1077, in do_handshake
self._sslobj.do_handshake()
File "/usr/local/lib/python3.6/ssl.py", line 689, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)