Tal_87_il
Tal_87_il

Reputation: 39

BlobServiceClient.from_connection_string(connect_str) error

I am trying to upload JSON file into a new container on Azure blob Storage account. I use Microsoft quick guide Currently my code looks like this:

>import os, uuid
>from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient
>connect_str = os.getenv('AZURE_STORAGE_CONNECTION_STRING')

So far It's works OK but when I add this line
>blob_service_client = BlobServiceClient.from_connection_string(connect_str)

I get an error message:

>(base) "`my file path`"
Traceback (most recent call last):
  File "`my file path`", line 14, in <module>
    blob_service_client = BlobServiceClient.from_connection_string(connect_str)
  File `".../anaconda3/lib/python3.8/site-packages/azure/storage/blob/_blob_service_client.py"`, line 174, in from_connection_string
    account_url, secondary, credential = parse_connection_str(conn_str, credential, 'blob')
  File `".../anaconda3/lib/python3.8/site-packages/azure/storage/blob/_shared/base_client.py"`, line 363, in parse_connection_str
    conn_str = conn_str.rstrip(";")
AttributeError: 'NoneType' object has no attribute 'rstrip'

I had wrote the same code on my PC and about a month ago I moved to Mac OS. I thought I did all the relevant adjustments, but apparently not. Since this mac is completely new I think I missing a few packages or maybe hav the wrong versions of the packages.

I am attaching pip list:

azure-common 1.1.27

azure-core 1.12.0

azure-nspkg 3.0.2

azure-storage 0.36.0

azure-storage-blob 12.9.0

Thank you!

Upvotes: 1

Views: 4902

Answers (1)

Donald Gedeon
Donald Gedeon

Reputation: 325

Your environment variable is probably not found. Try this code

connect_str = os.environ['AZURE_STORAGE_CONNECTION_STRING']

It should raise a KeyError or return None. I think you should be sure the variable is really read or that its value is not None.

Upvotes: 1

Related Questions