0

I was following along this article: Quickstart: Manage blobs with Python v12 SDK and the documentation for ContainerClient.upload_blob

Here's the snippet to upload a blob with this directory structure: testcontainer / backup / HelloWorld.cab

bsc = BlobServiceClient.from_connection_string('<connection-string>')
cc = bsc.get_container_client('testcontainer')
cc.upload_blob(name='testcontainer/backup/HelloWorld.cab', data=open(r"\\network\path\to\backup\HelloWorld.cab", 'rb').read())

But I get the following error. Any ideas on what I'm doing wrong?

azure.storage.blob._generated.models._models_py3.StorageErrorException: Operation returned an invalid status 'The specifed resource name contains invalid characters.'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python3\lib\site-packages\azure\core\tracing\decorator.py", line 83, in wrapper_use_tracer
    return func(*args, **kwargs)
  File "C:\Python3\lib\site-packages\azure\storage\blob\_container_client.py", line 836, in upload_blob
    blob.upload_blob(
  File "C:\Python3\lib\site-packages\azure\core\tracing\decorator.py", line 83, in wrapper_use_tracer
    return func(*args, **kwargs)
  File "C:\Python3\lib\site-packages\azure\storage\blob\_blob_client.py", line 496, in upload_blob
    return upload_block_blob(**options)
  File "C:\Python3\lib\site-packages\azure\storage\blob\_upload_helpers.py", line 153, in upload_block_blob
    process_storage_error(error)
  File "C:\Python3\lib\site-packages\azure\storage\blob\_shared\response_handlers.py", line 147, in process_storage_error
    raise error
azure.core.exceptions.HttpResponseError: The specifed resource name contains invalid characters.
RequestId:71cad76d-801e-0097-8068-1fc9e0000000
Time:2020-05-01T03:28:33.5320153Z
ErrorCode:InvalidResourceName
Error:None

Note: I also saw this answer to this question: Microsoft Azure: How to create sub directory in a blob container

yasouser
  • 5,113
  • 2
  • 27
  • 41

1 Answers1

1

I am able to reproduce this issue if I use invalid resource name (which is what the error message is telling you).

For example, if I use testcontainer as my blob container name (which is correct), I am able to upload the blob.

However if I use testContainer as my blob container name (which is invalid, notice the uppercase "C"), I get the same error as you're getting.

Please check the name of the blob container and the blob. Please see this link for naming convention for blob resources: https://learn.microsoft.com/en-us/rest/api/storageservices/naming-and-referencing-containers--blobs--and-metadata.

Gaurav Mantri
  • 128,066
  • 12
  • 206
  • 241
  • The error was due to a typo in the container name. Instead of `test-assets` I've typed `tests-asset`. – yasouser May 01 '20 at 06:29