Refer to the following article, when using BigQuery from Google APIs Client for Python, an error related to OAuth authentication occurred, so I will leave a solution. It seems that it happened because the file permissions could not read the file cacerts.txt, which defines the SSL certificates that can be connected.
Use BigQuery from python. http://qiita.com/shibacow/items/b8f6445058b374291be5
Using OAuth 2.0 for Server to Server Applications https://developers.google.com/api-client-library/python/auth/service-accounts
OSX 10.10.3 Python 2.7.6 httplib2 0.9.1 google-api-python-client 1.4.1
When using the Google APIs Client Library for Python and using the P12 file and using BigQuery, an authentication-related error occurred and the API could not be accessed.
ssl.SSLError: [Errno 185090050] _ssl.c:343: error:0B084002:x509 certificate routines:X509_load_cert_crl_file:system lib
The executed file is as follows.
bq-access.py
import json
from httplib2 import Http
from oauth2client.client import SignedJwtAssertionCredentials
from apiclient.discovery import build
SERVICE_ACCOUNT_EMAIL = '**********@developer.gserviceaccount.com'
PROJECT_NUMBER = '**********'
KEYFILE='******************.p12'
with open(KEYFILE) as f:
private_key = f.read()
credentials = SignedJwtAssertionCredentials(
SERVICE_ACCOUNT_EMAIL, private_key,
'https://www.googleapis.com/auth/bigquery')
http = Http()
credentials.authorize(http)
service = build('bigquery', 'v2', http=http)
response = service.datasets().list(projectId='************').execute()
print response
The following page was very helpful.
PYTHON OAUTH2 FAILING WITH X509 ERROR http://bretthutley.com/tag/mac-osx/
It was said that there was a problem with the permissions of the file cacerts.txt of http2lib, so when I looked it up, it was certainly not readable unless it was a group called wheel.
> cd /Library/Python/2.7/site-packages/httplib2-0.9.1-py2.7.egg/httplib2/
> ls -l cacerts.txt
-rw-r----- 1 root wheel 134862 7 13 18:36 cacerts.txt
Therefore, when I changed the file permissions with the chmod command as follows, I was able to access it without any problems.
> sudo chmod 644 cacerts.txt
Recommended Posts