Azure Python SDK: BlobServiceClient.get_container_client returning TypeError?

This is baffling me. I must be missing something obvious. Just trying to get a ContainerClient from a BlobServiceClient.

Example:

import os
import logging
from azure.storage.blob import BlobServiceClient, BlobClient

conn_string = "connection-string-here"
cont_name = "cont-test"

blob_svc_client = BlobServiceClient.from_connection_string(conn_string)

blob_cont_client = BlobServiceClient.get_container_client(cont_name)

Returns:

C:UsersuserDesktop>python myProgram.py
Traceback (most recent call last):
  File "C:UsersuserDesktopmyProgram.py", line 11, in <module>
    blob_cont_client = BlobServiceClient.get_container_client(cont_name)
TypeError: get_container_client() missing 1 required positional argument: 'container'
  • But get_container_client() is not missing the positionaly argument ‘container’.

Why is this happening?

Answer

I have modified your code by adding the extension to blob_svc_client with get_container_client variable. Below is the updated code:

import os
import logging
from azure.storage.blob import BlobServiceClient, BlobClient

conn_string = "connection-string-here"
cont_name = "cont-test"

blob_svc_client = BlobServiceClient.from_connection_string(conn_string)

blob_cont_client = blob_svc_client.get_container_client(cont_name)

I have reproduced your error as below:

Error

Below is the fixed screenshot:

enter image description here