pyOpenSSL NotImplementedError Google App Engine
Asked Answered
C

1

5

I'm trying to download some data using Google Analytics Reporting API V4.

Inside my lib/ folder (on the GAE project) I have pyOpenSSL and all its dependencies.

Locally, in my virtualenv, it works fine.

That's the error I'm getting:

Environment:


Request Method: GET
Request URL: ###############

Django Version: 1.9
Python Version: 2.7.5
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'polls')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'django.middleware.security.SecurityMiddleware')



Traceback:

File "/base/data/home/apps/myapp/1.394185263495829842/lib/django/core/handlers/base.py" in get_response
  149.                     response = self.process_exception_by_middleware(e, request)

File "/base/data/home/apps/myapp/1.394185263495829842/lib/django/core/handlers/base.py" in get_response
  147.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/base/data/home/apps/myapp/1.394185263495829842/polls/views.py" in index
  27.     return HttpResponse(json.dumps(we.atualizacao_diaria()))

File "lib/workers/worker_estacio.py" in atualizacao_diaria
  41.         return self.atualizar_periodo(f_date, f_date)

File "lib/workers/worker_estacio.py" in atualizar_periodo
  47.         c_ga_estacio = ConectorEstacioGA()

File "lib/workers/conectores/conector_ga.py" in __init__
  50.         credentials = ServiceAccountCredentials.from_p12_keyfile(SERVICE_ACCOUNT_EMAIL, KEY_FILE_LOCATION, scopes=SCOPES)

File "lib/oauth2client/service_account.py" in from_p12_keyfile
  345.             token_uri=token_uri, revoke_uri=revoke_uri)

File "lib/oauth2client/service_account.py" in _from_p12_keyfile_contents
  300.             raise NotImplementedError(_PKCS12_ERROR)

Exception Type: NotImplementedError at /
Exception Value: 
This library only implements PKCS#12 support via the pyOpenSSL library.
Either install pyOpenSSL, or please convert the .p12 file
to .pem format:
    $ cat key.p12 | \
    >   openssl pkcs12 -nodes -nocerts -passin pass:notasecret | \
    >   openssl rsa > key.pem

Could someone help me please?

Curse answered 14/7, 2016 at 0:11 Comment(2)
Base on your error have you already tried changing the file type to .p12 file? As suggested in the error report? Also check this Service Account documentation for further information.Derogatory
Yeah, I've tried. I think this is pretty much an app engine problem, the whole thing works fine in my test machine, it breaks down when I deploy to production. I'm not saying app engine has a problem, I'm saying I'm missing something about how to use pyOpenSSL there :)Curse
C
14

I have no clue about how to install the proper libs in GAE for use the .p12 key.

I solved it using the .json key which is available for download in the same place as the .p12:

enter image description here

Then, it is important to change the ServiceAccountCredentials constructor:

credentials = ServiceAccountCredentials.from_p12_keyfile(SERVICE_ACCOUNT_EMAIL, KEY_FILE_LOCATION_P12, scopes=SCOPES)

Must be replaced by:

credentials = ServiceAccountCredentials.from_json_keyfile_name(KEY_FILE_LOCATION_JSON, scopes=SCOPES)

I hope that might help somebody :)

Curse answered 20/7, 2016 at 18:17 Comment(1)
This is the best and most up-to-date solution, I've tried installing pyOpenSSL Library as suggested by the debugger but it didn't work either so I used @Thiago's solution and it worked fine.Neddie

© 2022 - 2024 — McMap. All rights reserved.