我使用python的google-cloud
客戶端下載從谷歌雲存儲(GCS)的文件,得到以下錯誤:GCS - DataCorruption:校驗錯配,同時下載
File "/deploy/app/scanworker/storagehandler/gcshandler.py" line 62 in download_object
blob.download_to_file(out_file)
File "/usr/local/lib/python3.5/dist-packages/google/cloud/storage/blob.py" line 464 in download_to_file self._do_download(transport, file_obj, download_url, headers)
File "/usr/local/lib/python3.5/dist-packages/google/cloud/storage/blob.py" line 418 in _do_download
download.consume(transport)
File "/usr/local/lib/python3.5/dist-packages/google/resumable_media/requests/download.py" line 169 in consume
self._write_to_stream(result)
File "/usr/local/lib/python3.5/dist-packages/google/resumable_media/requests/download.py" line 132 in _write_to_stream [args] [locals]
raise common.DataCorruption(response, msg)
DataCorruption: Checksum mismatch while downloading:
https://www.googleapis.com/download/storage/v1/b/<my-bucket>/o/<my-object>?alt=media
The X-Goog-Hash header indicated an MD5 checksum of:
fdn2kKmS4J6LCN6gfmEUVQ==
but the actual MD5 checksum of the downloaded contents was:
C9+ywW2Dap0gEv5gHoR1UQ==
我用下面的代碼下載從GCS BLOB:
bucket_name = '<some-bucket>'
service_account_key = '<path to json credential file>'
with open(service_account_key, 'r') as f:
keyfile = json.load(f)
project_id = keyfile['project_id']
credentials = service_account.Credentials.from_service_account_file(service_account_key)
client = storage.Client(project=project_id,
credentials=credentials)
bucket = client.get_bucket(bucket_name)
blob_name = '<name of blob>'
download_path = "./foo.obj"
blob = bucket.blob(blob_name)
with open(download_path, "w") as out_file:
blob.download_to_file(out_file) # it fails here
一些信息:
- 使用python3
- 使用與鼠
還下載了谷歌雲客戶端庫版本0.27.0在Kubernetes
這是客戶端庫的錯誤嗎?或者它可能是一個網絡問題? 嘗試下載不同的文件,所有文件都給出了來自Kubernetes的相同錯誤。相同的代碼已經運行好幾個月沒有問題,現在只能看到這個錯誤。
編輯:
重建是完全相同的代碼泊塢窗容器,似乎之前已經解決了這一問題。儘管如此,我仍然對導致錯誤的原因感到好奇。
編輯2: 我們使用circleci將webapp部署到生產環境。現在看起來像circleci上的圖像失敗了,而在本地構建它似乎工作。既然它包含在一個Docker容器中,這真的很奇怪,應該不是我們從哪裏構建的?
編輯3: 登錄到在kubernetes給上述錯誤非常相同的容器,我試圖運行gsutil cp gs:/<bucket>/<blob-name> foo.obj
此運行,沒有任何問題
您下載的對象是否將其內容編碼設置爲gzip?如果是這樣,這是我們對google-cloud-resumable-media庫進行的最近更改中的一個問題,可以添加校驗和支持(但是當前校驗和是gunzipped內容,而服務將爲gzip內容發送校驗和)。我們現在正在修復一個修復程序。 –
@MikeSchwartz:我在應用程序引擎應用程序中使用相同的庫google.cloud.storage,即google-cloud == 0.25.0。我還將google-resumable-media == 0.2.3添加到我的依賴列表中以部署在應用引擎上。 –
@MikeSchwartz:每當應用程序嘗試下載大於32 MB的文件時,我都會得到相同的DataCorruption:下載時校驗和不匹配: 錯誤。 我瞭解大於32 MB的文件無法在應用程序引擎中處理。這是否意味着存儲庫在內部嘗試gzip大於32MB的文件,因此我遇到校驗和比較錯誤?這是我即將做的:client = storage.Client(project ='myproj') bucket = client.get_bucket(bucket_name) blob = Blob(file_name,bucket) file = blob.download_as_string() –