AttributeError:'module'对象没有属性'SignedJwtAssertionCredentials'

时间:2016-02-25 17:22:53

标签: android python attributeerror oauth2client google-play-developer-api

问题:我一直在使用Python Script Samples by Google将apk上传到Play商店,并获取通过我的帐户发布的应用列表(list_apks.py和{{1} })。然而最近它开始打破。我尝试通过执行upload_apk.py来更新google-api-python-clientoath2client等软件包,但它没有帮助。

日志

这个如果列出apk的时候:

pip install --update packagename

这是上传apk时的内容:

Determining latest version for my.package.name...
error   25-Feb-2016 06:30:52    Traceback (most recent call last):
error   25-Feb-2016 06:30:52      File "list_apks.py", line 80, in <module>
error   25-Feb-2016 06:30:52        main()
error   25-Feb-2016 06:30:52      File "list_apks.py", line 46, in main
error   25-Feb-2016 06:30:52        credentials = client.SignedJwtAssertionCredentials(
error   25-Feb-2016 06:30:52    AttributeError: 'module' object has no attribute 'SignedJwtAssertionCredentials'
build   25-Feb-2016 06:30:52    Found latest APK version: 
build   25-Feb-2016 06:30:52    Generated new APK version: 1

代码片段

25-Feb-2016 06:33:30    Uploading APK...
25-Feb-2016 06:33:30    Traceback (most recent call last):
25-Feb-2016 06:33:30      File "upload_apk.py", line 115, in <module>
25-Feb-2016 06:33:30        main(sys.argv)
25-Feb-2016 06:33:30      File "upload_apk.py", line 62, in main
25-Feb-2016 06:33:30        credentials = client.SignedJwtAssertionCredentials(
25-Feb-2016 06:33:30    AttributeError: 'module' object has no attribute 'SignedJwtAssertionCredentials'

我还能尝试什么?我很感激你的帮助。

2 个答案:

答案 0 :(得分:22)

经过这么多天,我才能找到答案。事实证明,类SignedJwtAssertionCredentials已从oath2client更新中的2.0.0 python包中删除。它不再是oauth2client.client。该行为已移至oauth2client.service_account.ServiceAccountCredentials

以下为我工作:

import argparse

from apiclient.discovery import build
from oauth2client.service_account import ServiceAccountCredentials

import httplib2
from oauth2client import client

SERVICE_ACCOUNT_EMAIL = ('myaccountemail.com')

# Declare command-line flags.
argparser = argparse.ArgumentParser(add_help=False)
argparser.add_argument('package_name',
                   help='The package name. Example: com.android.sample')

def main():
  key='mykeyname.p12'
  scope = 'https://www.googleapis.com/auth/androidpublisher'

  credentials = ServiceAccountCredentials.from_p12_keyfile(
      SERVICE_ACCOUNT_EMAIL,
      key,
      scopes=[scope]
  )
  http = httplib2.Http()
  http = credentials.authorize(http)
  ....

来源:

答案 1 :(得分:0)

我遇到了同样的问题,并且我没有安装pyOpenSSL ,这在使用from_p12_keyfile()时是必需的。

from_p12_keyfile()

提高:
NotImplementedError如果未安装pyOpenSSL / 活动的密码库。

我将JSON文件读入字典,并像这样传递给from_json_keyfile_dict()

import json
from oauth2client.service_account import ServiceAccountCredentials
# other imports and code from sample...

# modified authentication part
data = {}
with open('api.json') as json_file:
  data = json.load(json_file)
credentials = ServiceAccountCredentials.from_json_keyfile_dict(
    data,
    scopes=['https://www.googleapis.com/auth/androidpublisher']
)
http = httplib2.Http()
http = credentials.authorize(http)
# do what ever you want with the returned object

api.json文件是指在创建服务帐户时创建的文件。

当然,还有其他一些功能可以获取凭据,但是此解决方案帮助我使这些东西正常运行。也许这会对以后的人有所帮助。

参考:Oauth2Client.service_account