I am trying to create a service account app so that I can access Google Analytics api using Python.
Two things are confusing me. First, when I use the following code:
`from oauth2client.client import SignedJwtAssertionCredentials
client_email = "#####client_email#######.gserviceaccount.com"
with open("XXXXXX.p12") as f:
private_key = f.read()
credentials = SignedJwtAssertionCredentials(client_email, private_key,'https://www.googleapis.com/auth/sqlservice.admin')`
I get the following error:
`oauth2client.client.CryptoUnavailableError: No crypto library available`
After doing a little research I found that this might have to do with granting the app domain-wide authority to the service account. However, when I log on to the Google Developers Console I cannot locate the security icon or the more-options button. Any help much appreciated thank you.
That error probably means you need the python-openssl package.
apt-get install python-openssl
This did the trick for me (without converting to PEM):
pip install PyOpenSSL
pip freeze
says I have version 0.15.1
Even if you are installed pycrypto & python-ssl libraries in your development environment, You need to add this pycrypto
library in your application's app.yaml
file.
libraries:
- name: pycrypto
version: "latest"
I just recently set this up but opted to go with PyCrypto 2.6.1, but you can also use python-openssl as mentioned in the previous answer.
The only problem I had and I can't pinpoint this down, but the P12 key generated by the Google Developer Console wasn't working with my Service Account API call (to the Content API for Shopping), and I had to switch the key to the PEM format to get things going.
My setup: (Win7, python 2.7.x, PyCrypto 2.6.1)
The error I got when trying to use the P12 key, but later resolved when converting it to PEM:
Error 3: PKCS12 format is not supported by the PyCrypto library.
NotImplementedError: PKCS12 format is not supported by the PyCrypto library. Try converting to a “PEM” (openssl pkcs12 -in xxxxx.p12 -nodes -nocerts > privatekey.pem) or using PyOpenSSL if native code is an option.
One important thing, don't forget to go inside Google Analytics and grant the appropriate permissions for the client email address that is created during the creation of the Service Account.
OSX 10.11 El Capitan does not distribute OpenSSL anymore. I was able to install cryptography
using Homebrew and static build:
env CRYPTOGRAPHY_OSX_NO_LINK_FLAGS=1 LDFLAGS="$(brew --prefix openssl)/lib/libssl.a $(brew --prefix openssl)/lib/libcrypto.a" CFLAGS="-I$(brew --prefix openssl)/include" pip install cryptography
More info
- http://cryptography.readthedocs.org/en/latest/installation/