SSL: CERTIFICATE_VERIFY_FAILED with Bigquery

时间:2017-06-19 13:58:04

标签: python-3.x ssl-certificate google-bigquery

I'm trying to query data from Bigquery within Python environment.

I created my credential using a service account by following this step from Bigquery website and used the following code.

from google.cloud import bigquery

client = bigquery.Client()
SQLCommand = '''
             Some sql command '''

query_results = client.run_sync_query(SQLCommand)
query_results.run()

However, I'm encountering the following error and I'm not sure where to look at to fix this issue. Any suggestion would be appreciated!

Traceback (most recent call last):

File "<ipython-input-11-88c61e8cf342>", line 1, in <module>
  query_results.run()

File "c:\users\xxxx\appdata\local\continuum\anaconda\lib\site-    packages\google_cloud_bigquery-0.24.0-py2.7.egg\google\cloud\bigquery\query.py", line 364, in run
method='POST', path=path, data=self._build_resource())

File "c:\users\xxxx\appdata\local\continuum\anaconda\lib\site-packages\google_cloud_core-0.24.1-py2.7.egg\google\cloud\_http.py", line 299, in api_request
headers=headers, target_object=_target_object)

File "c:\users\xxxx\appdata\local\continuum\anaconda\lib\site-packages\google_cloud_core-0.24.1-py2.7.egg\google\cloud\_http.py", line 193, in _make_request
return self._do_request(method, url, headers, data, target_object)

File "c:\users\xxxx\appdata\local\continuum\anaconda\lib\site-packages\google_cloud_core-0.24.1-py2.7.egg\google\cloud\_http.py", line 223, in _do_request
body=data)

File "build\bdist.win-amd64\egg\google_auth_httplib2.py", line 187, in request
self._request, method, uri, request_headers)

File "c:\users\xxxx\appdata\local\continuum\anaconda\lib\site-packages\google_auth-1.0.1-py2.7.egg\google\auth\credentials.py", line 121, in before_request
self.refresh(request)

File "c:\users\xxxx\appdata\local\continuum\anaconda\lib\site-packages\google_auth-1.0.1-py2.7.egg\google\oauth2\service_account.py", line 310, in refresh
request, self._token_uri, assertion)

File "c:\users\xxxx\appdata\local\continuum\anaconda\lib\site-packages\google_auth-1.0.1-py2.7.egg\google\oauth2\_client.py", line 143, in jwt_grant
response_data = _token_endpoint_request(request, token_uri, body)

File "c:\users\xxxx\appdata\local\continuum\anaconda\lib\site-packages\google_auth-1.0.1-py2.7.egg\google\oauth2\_client.py", line 104, in _token_endpoint_request
method='POST', url=token_uri, headers=headers, body=body)

File "build\bdist.win-amd64\egg\google_auth_httplib2.py", line 119, in __call__
raise exceptions.TransportError(exc)

TransportError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:661)
[1]: https://cloud.google.com/docs/authentication/getting-started

1 个答案:

答案 0 :(得分:0)

我怀疑这不是BigQuery特定的,这个问题的答案之一可能是相关的:

urllib and "SSL: CERTIFICATE_VERIFY_FAILED" Error

基本上,根证书默认情况下不会与某些版本的Python一起安装,您需要在安装后步骤中执行此操作。如果没有根证书,HTTPS客户端将无法检查远程服务器的身份。

简短版本,你可能需要这样做(取自链接的问题):

&#34; ReadMe将让您运行此安装后脚本,该脚本只安装certifi:/ Applications / Python \ 3.6 / Install \ Certificates.command&#34;