簡體   English   中英

解碼Google雲端存儲python API返回的protobuf文件

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

我正在嘗試通過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文件)。 有什么建議么?

這不是protobuf。 這是一個zip文件。 線索

  • 文件名是'sales / salesreport_201806.zip'
  • 前幾個字節包含“ PK”,(如PKZip所示

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM