AttributeError:“模块"对象没有属性"SignedJwtAssertionCredentials" [英] AttributeError: 'module' object has no attribute 'SignedJwtAssertionCredentials'

查看:187
本文介绍了AttributeError:“模块"对象没有属性"SignedJwtAssertionCredentials"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:我一直在使用 Python脚本示例,作者: Google ,将apk上传到Play商店,并获取通过我的帐户发布的应用列表(

Problem: I've been using Python Script Samples by Google to upload the apk to Play Store and to get list of apps published via my account (list_apks.py and upload_apk.py). However recently it started breaking. I've tried to update the packages like google-api-python-client, oath2client etc by doing pip install --update packagename but it didn't help.

日志:

这是在列出apk的情况下

This if while listing apk's:

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

这是在上传apk时:

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'

代码段:

import argparse

from apiclient.discovery import build
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():
  # Load the key in PKCS 12 format that you downloaded from the Google APIs
  # Console when you created your Service account.
  f = file('mykeyname.p12', 'rb')
  key = f.read()
  f.close()

  # HERE IS THE EXCEPTION 
  credentials = client.SignedJwtAssertionCredentials(
      SERVICE_ACCOUNT_EMAIL,
      key,
      scope='https://www.googleapis.com/auth/androidpublisher')
  http = httplib2.Http()
  http = credentials.authorize(http)
  ...

我还能尝试什么?非常感谢您的帮助.

What else I can try? I would appreciate your help.

推荐答案

最后几天,我终于找到了答案.事实证明,在2.0.0更新中从oath2client python包中删除了类SignedJwtAssertionCredentials. oauth2client.client下不再存在.该行为已移至oauth2client.service_account.ServiceAccountCredentials.

Finally after so many days, I was able to find answer to it. It turns out that the class SignedJwtAssertionCredentials was removed from the oath2client python package in the 2.0.0 update. It was no more under oauth2client.client. The behaviour has been moved onto 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)
  ....

来源:

oauth2client-Release 2.0.0

这篇关于AttributeError:“模块"对象没有属性"SignedJwtAssertionCredentials"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆