Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

az storage blob upload fails with --content-md5 fails on azure-cli 2.34.0 #21494

Closed
pkoziol opened this issue Mar 2, 2022 · 4 comments · Fixed by #21523
Closed

az storage blob upload fails with --content-md5 fails on azure-cli 2.34.0 #21494

pkoziol opened this issue Mar 2, 2022 · 4 comments · Fixed by #21523
Assignees
Labels
Auto-Assign Auto assign by bot customer-reported Issues that are reported by GitHub users external to the Azure organization. Storage az storage
Milestone

Comments

@pkoziol
Copy link

pkoziol commented Mar 2, 2022

Describe the bug

Command Name
az storage blob upload ... --content-md5 ...

Errors:

The command failed with an unexpected error. Here is the traceback:
blob_content_md5 must be type bytearray.
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/msrest/serialization.py", line 765, in serialize_data
    return self.serialize_type[data_type](data, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/msrest/serialization.py", line 1015, in serialize_bytearray
    return b64encode(attr).decode()
  File "/usr/local/lib/python3.10/base64.py", line 58, in b64encode
    encoded = binascii.b2a_base64(s, newline=False)
TypeError: a bytes-like object is required, not 'str'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/msrest/serialization.py", line 717, in header
    output = self.serialize_data(data, data_type, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/msrest/serialization.py", line 780, in serialize_data
    raise_with_traceback(
  File "/usr/local/lib/python3.10/site-packages/msrest/exceptions.py", line 51, in raise_with_traceback
    raise error.with_traceback(exc_traceback)
  File "/usr/local/lib/python3.10/site-packages/msrest/serialization.py", line 765, in serialize_data
    return self.serialize_type[data_type](data, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/msrest/serialization.py", line 1015, in serialize_bytearray
    return b64encode(attr).decode()
  File "/usr/local/lib/python3.10/base64.py", line 58, in b64encode
    encoded = binascii.b2a_base64(s, newline=False)
msrest.exceptions.SerializationError: Unable to serialize value: 'y3N9S9wst5SO/myHRqM1uQ==' as type: 'bytearray'., TypeError: a bytes-like object is required, not 'str'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/knack/cli.py", line 231, in invoke
    cmd_result = self.invocation.execute(args)
  File "/usr/local/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 658, in execute
    raise ex
  File "/usr/local/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 721, in _run_jobs_serially
    results.append(self._run_job(expanded_arg, cmd_copy))
  File "/usr/local/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 713, in _run_job
    return cmd_copy.exception_handler(ex)
  File "/usr/local/lib/python3.10/site-packages/azure/cli/command_modules/storage/__init__.py", line 380, in new_handler
    first(ex)
  File "/usr/local/lib/python3.10/site-packages/azure/cli/command_modules/storage/__init__.py", line 380, in new_handler
    first(ex)
  File "/usr/local/lib/python3.10/site-packages/azure/cli/command_modules/storage/_exception_handler.py", line 17, in file_related_exception_handler
    raise ex
  File "/usr/local/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 692, in _run_job
    result = cmd_copy(params)
  File "/usr/local/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 328, in __call__
    return self.handler(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/azure/cli/core/commands/command_operation.py", line 121, in handler
    return op(**command_args)
  File "/usr/local/lib/python3.10/site-packages/azure/cli/command_modules/storage/operations/blob.py", line 547, in upload_blob
    response = client.upload_blob(data=stream, length=length, metadata=metadata,
  File "/usr/local/lib/python3.10/site-packages/azure/core/tracing/decorator.py", line 83, in wrapper_use_tracer
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/azure/multiapi/storagev2/blob/v2020_10_02/_blob_client.py", line 713, in upload_blob
    return upload_block_blob(**options)
  File "/usr/local/lib/python3.10/site-packages/azure/multiapi/storagev2/blob/v2020_10_02/_upload_helpers.py", line 99, in upload_block_blob
    return client.upload(
  File "/usr/local/lib/python3.10/site-packages/azure/multiapi/storagev2/blob/v2020_10_02/_generated/operations/_block_blob_operations.py", line 195, in upload
    header_parameters['x-ms-blob-content-md5'] = self._serialize.header("blob_content_md5", _blob_content_md5, 'bytearray')
  File "/usr/local/lib/python3.10/site-packages/msrest/serialization.py", line 721, in header
    raise TypeError("{} must be type {}.".format(name, data_type))
TypeError: blob_content_md5 must be type bytearray.

To Reproduce:

  • echo 12765 > /tmp/upload-test-12765.txt
  • openssl dgst -md5 -binary /tmp/upload-test-12765.txt | base64
  • az storage blob upload --verbose --container-name stuff-and-things --file /tmp/upload-test-12765.txt --content-md5 y3N9S9wst5SO/myHRqM1uQ== --name dev/test-12765.txt

Expected Behavior

Should not fail.
It works on 2.33.1.
On 2.34.0 it works without --content-md5 option.

Environment Summary

Linux-5.10.76-linuxkit-x86_64-with, Alpine Linux v3.15
Python 3.10.2
Installer: PIP

azure-cli 2.34.0

Additional Context

@ghost ghost added customer-reported Issues that are reported by GitHub users external to the Azure organization. Storage az storage labels Mar 2, 2022
@ghost ghost added this to the Backlog milestone Mar 2, 2022
@ghost ghost assigned evelyn-ys Mar 2, 2022
@ghost ghost added the Auto-Assign Auto assign by bot label Mar 2, 2022
@yonzhan
Copy link
Collaborator

yonzhan commented Mar 2, 2022

storage

@aslushnikov
Copy link

We got hit by this as well. Pinned to 2.33.1 so far as a workaround.

@evelyn-ys
Copy link
Member

@calvinhzy to have a look

@calvinhzy
Copy link
Member

The --content-md5 flag is currently not working properly. Sorry for the inconvenience.
You can try adding storage-blob-preview extension with: az extension add -n storage-blob-preview.
Alternatively, you can pin to the previous version or skip this flag.
We will have this fixed in the next release. Again sorry for the inconvenience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Assign Auto assign by bot customer-reported Issues that are reported by GitHub users external to the Azure organization. Storage az storage
Projects
None yet
5 participants