就像總結一樣,我試圖用Microsoft Azure存儲瀏覽器工具來驗證上述例外情況。
當用戶上傳壓縮類型的文件,如果設置編碼類型屬性gzip的。
在下載時,客戶端會檢查文件類型是否可以是鬱悶編碼類型,如果dismatch會出現如下異常:
Traceback (most recent call last):
File "D:\Python35\lib\site-packages\urllib3\response.py", line 266, in _decode
data = self._decoder.decompress(data)
File "D:\Python35\lib\site-packages\urllib3\response.py", line 66, in decompress
return self._obj.decompress(data)
zlib.error: Error -3 while decompressing data: incorrect header check
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\Python35\lib\site-packages\requests\models.py", line 745, in generate
for chunk in self.raw.stream(chunk_size, decode_content=True):
File "D:\Python35\lib\site-packages\urllib3\response.py", line 436, in stream
data = self.read(amt=amt, decode_content=decode_content)
File "D:\Python35\lib\site-packages\urllib3\response.py", line 408, in read
data = self._decode(data, decode_content, flush_decoder)
File "D:\Python35\lib\site-packages\urllib3\response.py", line 271, in _decode
"failed to decode it." % content_encoding, e)
urllib3.exceptions.DecodeError: ('Received response with content-encoding: gzip, but failed to decode it.', error('Error -3 while decompressing data: incorrect header check',))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\Python35\lib\site-packages\azure\storage\storageclient.py", line 222, in _perform_request
response = self._httpclient.perform_request(request)
File "D:\Python35\lib\site-packages\azure\storage\_http\httpclient.py", line 114, in perform_request
proxies=self.proxies)
File "D:\Python35\lib\site-packages\requests\sessions.py", line 508, in request
resp = self.send(prep, **send_kwargs)
File "D:\Python35\lib\site-packages\requests\sessions.py", line 658, in send
r.content
File "D:\Python35\lib\site-packages\requests\models.py", line 823, in content
self._content = bytes().join(self.iter_content(CONTENT_CHUNK_SIZE)) or bytes()
File "D:\Python35\lib\site-packages\requests\models.py", line 750, in generate
raise ContentDecodingError(e)
requests.exceptions.ContentDecodingError: ('Received response with content-encoding: gzip, but failed to decode it.', error('Error -3 while decompressing data: incorrect header check',))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:/PythonWorkSpace/AzureStorage/BlobStorage/CreateContainer.py", line 20, in <module>
f)
File "D:\Python35\lib\site-packages\azure\storage\blob\baseblobservice.py", line 1932, in get_blob_to_stream
_context=operation_context)
File "D:\Python35\lib\site-packages\azure\storage\blob\baseblobservice.py", line 1659, in _get_blob
operation_context=_context)
File "D:\Python35\lib\site-packages\azure\storage\storageclient.py", line 280, in _perform_request
raise ex
File "D:\Python35\lib\site-packages\azure\storage\storageclient.py", line 252, in _perform_request
raise AzureException(ex.args[0])
azure.common.AzureException: ('Received response with content-encoding: gzip, but failed to decode it.', error('Error -3 while decompressing data: incorrect header check',))
Process finished with exit code 1
解決方案:
作爲@Gaurav Mantri帆,您可以將EncodingType屬性設置爲無或確保EncodingType設置與文件本身的類型匹配。
此外,您可以參考SO線程python making POST request with JSON data。
你可以檢查blob的屬性,特別是內容編碼屬性值嗎?如果它設置爲gzip,只需通過將其值設置爲空字符串來更新blob屬性即可。 –
工作!謝謝 –