1

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
user4279562
  • 669
  • 12
  • 25

1 Answers1

0

I suspect this isn't BigQuery specific and one of the answers to this question may be relevant:

urllib and "SSL: CERTIFICATE_VERIFY_FAILED" Error

Basically, the root certificates aren't install by default along with some versions of Python and you need to do that as part of a post-install step. Without the root certs, the HTTPS client has no way to check the identity of the remote server.

Short version, you probably need to do this (taken from the linked question):

"The ReadMe will have you run this post-install script, which just installs certifi: /Applications/Python\ 3.6/Install\ Certificates.command"

Adam Lydick
  • 1,092
  • 7
  • 15
  • I don't think that's why. I am using Python 2.7 and I have certifi installed. On Windows, the certificates are stored in ~\lib\site-packages\certifi\cacert.pem, which I have. Do I need to download a certificate from BigQuery too? – user4279562 Jun 28 '17 at 15:42