Search code examples
pythonpython-3.xazure-storageazure-blob-storage

Creating Container on Azure using Python


So I'm trying to create a new Container in Azure Storage. I want to store csv files as blobs that can be used to generate Power BI reports.

The first step itself is giving me an error. It is strange how the same code has worked in the past but is not working now.

Can you guys spot any error in this?

from azure.storage.blob import BlockBlobService, PublicAccess
block_blob_service = BlockBlobService(account_name='myaccount', account_key='mykey')
container_name ='decipher'
block_blob_service.create_container(container_name)

AzureException: HTTPSConnectionPool(host='myaccount%20.blob.core.windows.net', port=443): Max retries exceeded with url: /decipher?restype=container (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x000002D24D433CC0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))

Solution

  • I'd double check the imports required are installed: from azure.storage.blob import BlockBlobService , then trying from a different env, such as PS vs cmd, or Ubuntu terminal, this could be also from azure end if your request was dropped. I just tried and was able to create a container:

    from azure.storage.blob import BlockBlobService
    block_blob_service = BlockBlobService(account_name='storagename', account_key='somekey')
    container_name = 'adamnewcontainer'
    block_blob_service.create_container(container_name)