简体   繁体   English

解码Google云端存储python API返回的protobuf文件

[英]decode protobuf file returned by google cloud storage python api

I am trying to automatically download earnings report from Google Play through Google Cloud Storage and their client api library for python, googleapiclient . 我正在尝试通过Google Cloud Storage及其针对python的客户端API库googleapiclient从Google Play自动下载收益报告。

I use python 3.6.5 (Anaconda distribution) on Windows 10: 我在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()

However, I get some protocol buffer file as response , which starts like this: 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 ,其开始如下: 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'

I cannot figure out which decoder I should use to get response in a better format (when downloaded manually from Google Play, the report is .csv file in a .zip archive). 我无法弄清楚应该使用哪种解码器来获得更好的格式response (从Google Play手动下载时,报告是.zip存档中的.csv文件)。 Any suggestions? 有什么建议么?

This isn't a protobuf. 这不是protobuf。 It is a zip file. 这是一个zip文件。 The clues 线索

  • the filename is 'sales/salesreport_201806.zip' 文件名是'sales / salesreport_201806.zip'
  • the first few bytes contain "PK", (as in PKZip ) 前几个字节包含“ PK”,(如PKZip所示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python 3-Google protobuf响应-不带.proto文件的解码 - Python 3 - Google protobuf response - decode without .proto file Python会将文件存储到Google云端存储中 - Python urlretrieve a file to Google Cloud Storage 如何将文件上传到 Python 3 上的 Google Cloud Storage? - How to upload a file to Google Cloud Storage on Python 3? 将文件上传到Appengine上的Google Cloud Storage(Python) - File Upload To Google Cloud Storage on Appengine(Python) python和谷歌云存储 - python and google cloud storage 使用Python api-client-library将文本文件上传到Google Cloud Storage。 适用于图片,而非文字 - Upload text file to Google Cloud Storage with Python api-client-library. Works with image, not text 使用Python Blobstore API上传文件时选择Google Cloud Storage对象名称 - Choosing Google Cloud Storage object name when uploading a file using Python blobstore API Google Cloud Storage:Python API 使用通配符获取 blob 信息 - Google Cloud Storage : Python API get blob information with wildcard 如何使用 Python API 在 Google Cloud Storage 上上传文件夹 - How to upload folder on Google Cloud Storage using Python API 谷歌“正式”支持哪个 Python 云存储库/API? - Which Python Cloud Storage lib/API is "officially" supported by Google?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM