【问题标题】:decode protobuf file returned by google cloud storage python api解码谷歌云存储python api返回的protobuf文件
【发布时间】:2018-08-01 13:45:48
【问题描述】:

我正在尝试通过 Google Cloud Storage 和他们的 Python 客户端 API 库,googleapiclient,从 Google Play 自动下载收益报告。

我在 Windows 10 上使用 python 3.6.5(Anaconda 发行版):

client_email = '...@...iam.gserviceaccount.com'
json_file_path = 'C:\\Users\\...'
cloud_storage_bucket = 'pubsite_prod_rev_...'
report_to_download = 'sales/salesreport_201806.zip'

json_obj = json.loads(open(json_file).read())
_private_key = json_obj['private_key']
_private_key_id = json_obj['private_key_id']
_token_uri = json_obj['token_uri']
_client_id = json_obj['client_id']


credentials = ServiceAccountCredentials(
    service_account_email = client_email,
    private_key_id = _private_key_id,
    token_uri = _token_uri,
    client_id = _client_id,
    scopes = 'https://www.googleapis.com/auth/devstorage.read_only',
    signer = crypt.Signer.from_string(_private_key), )

storage = build('storage', 'v1', http=credentials.authorize(Http()))

request = storage.objects().get_media(bucket=cloud_storage_bucket,
                                      object=report_to_download)
response = request.execute()

但是,我得到一些协议缓冲区文件为response,它的开头是这样的: b'PK\x03\x04\x14\x00\x08\x08\x08\x00\xdb\xa3\xe4L\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x13\x00\x00\x00PlayApps_201806.csv'

我不知道应该使用哪个解码器以更好的格式获取 response(从 Google Play 手动下载时,报告是 .zip 存档中的 .csv 文件)。有什么建议吗?

【问题讨论】:

    标签: python google-cloud-storage google-play-console google-python-api


    【解决方案1】:

    这不是 protobuf。它是一个 zip 文件。线索

    • 文件名为“sales/salesreport_201806.zip”
    • 前几个字节包含“PK”,(如PKZip)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-29
      • 2017-09-05
      • 1970-01-01
      • 1970-01-01
      • 2019-03-22
      • 1970-01-01
      相关资源
      最近更新 更多