5

我正在尝试使用 Google Analytics Reporting API V4 下载一些数据。

在我的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

有人可以帮我吗?

4

1 回答 1

13

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

我使用 .json 密钥解决了这个问题,该密钥可在与 .p12 相同的位置下载:

在此处输入图像描述

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)

我希望这可能对某人有所帮助:)

于 2016-07-20T18:17:55.923 回答