azure-cli icon indicating copy to clipboard operation
azure-cli copied to clipboard

Azure storage blob not able to download files

Open abdullah353 opened this issue 7 years ago • 3 comments

Describe the bug I am trying to download the complete storage blob to my hard-disk. Running the following script with dryrun output all the files correctly:

az storage blob download-batch -d .  --source xxx --dryrun
download action: from xxx to .
    pattern None
  container xxx
      total 374
 operations
  - neo4j-2017-09-17-18:38.bak.tar.gz
  - neo4j-2017-09-17-19:24.bak.tar.gz
  - neo4j-2017-09-30-16:03.bak.tar.gz
  - neo4j-2017-09-30-16:20.bak.tar.gz
  - neo4j-2017-09-30-16:30.bak.tar.gz

But when i try to run without --dryrun it fails and throws the following error:

('Received response with content-encoding: gzip, but failed to decode it.', error('Error -3 while decompressing data: incorrect header check',))
Traceback (most recent call last):
  File "/opt/az/lib/python3.6/site-packages/urllib3/response.py", line 324, in _decode
    data = self._decoder.decompress(data)
  File "/opt/az/lib/python3.6/site-packages/urllib3/response.py", line 77, in decompress
    ret += 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 "/opt/az/lib/python3.6/site-packages/requests/models.py", line 750, in generate
    for chunk in self.raw.stream(chunk_size, decode_content=True):
  File "/opt/az/lib/python3.6/site-packages/urllib3/response.py", line 494, in stream
    data = self.read(amt=amt, decode_content=decode_content)
  File "/opt/az/lib/python3.6/site-packages/urllib3/response.py", line 466, in read
    data = self._decode(data, decode_content, flush_decoder)
  File "/opt/az/lib/python3.6/site-packages/urllib3/response.py", line 329, 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 "/opt/az/lib/python3.6/site-packages/azure/multiapi/storage/v2018_03_28/common/storageclient.py", line 269, in _perform_request
    response = self._httpclient.perform_request(request)
  File "/opt/az/lib/python3.6/site-packages/azure/multiapi/storage/v2018_03_28/common/_http/httpclient.py", line 92, in perform_request
    proxies=self.proxies)
  File "/opt/az/lib/python3.6/site-packages/requests/sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "/opt/az/lib/python3.6/site-packages/requests/sessions.py", line 686, in send
    r.content
  File "/opt/az/lib/python3.6/site-packages/requests/models.py", line 828, in content
    self._content = b''.join(self.iter_content(CONTENT_CHUNK_SIZE)) or b''
  File "/opt/az/lib/python3.6/site-packages/requests/models.py", line 755, 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 "/opt/az/lib/python3.6/site-packages/knack/cli.py", line 206, in invoke
    cmd_result = self.invocation.execute(args)
  File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 328, in execute
    raise ex
  File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 388, in _run_jobs_serially
    results.append(self._run_job(expanded_arg, cmd_copy))
  File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 378, in _run_job
    cmd_copy.exception_handler(ex)
  File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/storage/__init__.py", line 234, in new_handler
    handler(ex)
  File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/storage/__init__.py", line 177, in handler
    raise ex
  File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 357, in _run_job
    result = cmd_copy(params)
  File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 171, in __call__
    return self.handler(*args, **kwargs)
  File "/opt/az/lib/python3.6/site-packages/azure/cli/core/__init__.py", line 442, in default_command_handler
    return op(**command_args)
  File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/storage/operations/blob.py", line 161, in storage_blob_download_batch
    for blob_normed in blobs_to_download)
  File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/storage/operations/blob.py", line 161, in <genexpr>
    for blob_normed in blobs_to_download)
  File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/storage/operations/blob.py", line 134, in _download_blob
    progress_callback=progress_callback)
  File "/opt/az/lib/python3.6/site-packages/azure/multiapi/storage/v2018_03_28/blob/baseblobservice.py", line 1872, in get_blob_to_path
    timeout)
  File "/opt/az/lib/python3.6/site-packages/azure/multiapi/storage/v2018_03_28/blob/baseblobservice.py", line 2088, in get_blob_to_stream
    operation_context
  File "/opt/az/lib/python3.6/site-packages/azure/multiapi/storage/v2018_03_28/blob/_download_chunking.py", line 42, in _download_blob_chunks
    list(executor.map(downloader.process_chunk, downloader.get_chunk_offsets()))
  File "/opt/az/lib/python3.6/concurrent/futures/_base.py", line 586, in result_iterator
    yield fs.pop().result()
  File "/opt/az/lib/python3.6/concurrent/futures/_base.py", line 432, in result
    return self.__get_result()
  File "/opt/az/lib/python3.6/concurrent/futures/_base.py", line 384, in __get_result
    raise self._exception
  File "/opt/az/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/opt/az/lib/python3.6/site-packages/azure/multiapi/storage/v2018_03_28/blob/_download_chunking.py", line 94, in process_chunk
    chunk_data = self._download_chunk(chunk_start, chunk_end).content
  File "/opt/az/lib/python3.6/site-packages/azure/multiapi/storage/v2018_03_28/blob/_download_chunking.py", line 122, in _download_chunk
    _context=self.operation_context
  File "/opt/az/lib/python3.6/site-packages/azure/multiapi/storage/v2018_03_28/blob/baseblobservice.py", line 1750, in _get_blob
    operation_context=_context)
  File "/opt/az/lib/python3.6/site-packages/azure/multiapi/storage/v2018_03_28/common/storageclient.py", line 381, in _perform_request
    raise ex
  File "/opt/az/lib/python3.6/site-packages/azure/multiapi/storage/v2018_03_28/common/storageclient.py", line 311, 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',))

Expected behavior It should download all files from azure to my disk.

Additional context I am able to download the first file if I click the properties and remove the following key-values from file: ContentType: application/tar+gzip ContentEncoding: gzip

I have a lot of files and this doesn't seems to be a correct way to download the files.

abdullah353 avatar Jan 14 '19 20:01 abdullah353

@abdullah353 I was able to repro this. @zezha-msft can you help? Is there a way in the sdk to bypass this? To summarize, having the content settings: "contentEncoding": "gzip" and ContentType: application/tar+gzip blocks get_blob_to_path from properly downloading a blob.

williexu avatar Feb 01 '19 18:02 williexu

Hi @williexu, this is a known issue. There is a workaround, but we haven't integrated that into the SDK.

We are currently tracking this work item with this new issue.

zezha-msft avatar Feb 01 '19 22:02 zezha-msft

I've logged this item to be included in the next generation of the Storage SDK: https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/storage/azure-storage-blob.

It will be part of the GA criteria.

zezha-msft avatar Jul 31 '19 20:07 zezha-msft