3

我在尝试使用Google Analytics Reporting API V4下载一些数据。pyOpenSSL NotImplementedError Google App Engine

在我的lib/文件夹(在GAE项目中)我有pyOpenSSL及其所有依赖项。

本地,在我的virtualenv,它工作正常。

这是错误我得到:

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

有人能帮助我吗?

+0

此基础上你的错误你有没有尝试过更改文件类型.P12文件?正如错误报告中所建议的那样?还请查看此[服务帐户](https://developers.google.com/identity/protocols/OAuth2ServiceAccount)文档以获取更多信息。 –

+0

是的,我试过了。我认为这几乎是一个应用程序引擎问题,整个事情在我的测试机器中运行良好,在部署到生产环境时会崩溃。我不是说应用程序引擎有问题,我说我错过了关于如何使用pyOpenSSL的东西:) –

回答

9

我不知道如何在GAE中安装正确的库以使用.p12键。

我解决它使用以.json关键是可供下载在同一地点为中.P12:

enter image description here

然后,改变ServiceAccountCredentials构造是非常重要的

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

必须替换为:

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

我希望可以帮助别人:)