According to this MS-Document,
To obtain the Azure Blob storage connection for the Azure AI Foundry project, you need to use the include_credentials=False
parameter in your code.
Now, when I used the below code with include_credentials=False
and I got the output of blob storage connection and list of blobs.
Code:
from azure.identity import DefaultAzureCredential
from azure.ai.projects import AIProjectClient
from azure.ai.projects.models import ConnectionType
from azure.storage.blob import ContainerClient
from urllib.parse import urlparse
credential = DefaultAzureCredential()
client = AIProjectClient.from_connection_string(
conn_str="xxxx"
credential=credential
)
storage_connection = client.connections.get_default(
connection_type=ConnectionType.AZURE_BLOB_STORAGE,
include_credentials=False
)
print(storage_connection)
parsed = urlparse(storage_connection.endpoint_url)
account_name = parsed.netloc.split('.')[0]
account_url = f"https://{account_name}.blob.core.windows.net"
container_name = parsed.path.lstrip('/')
print("Account URL:", account_url)
print("Container Name:", container_name)
container_client = ContainerClient(
account_url=account_url,
container_name=container_name,
credential=credential
)
print(f"Blobs in container '{container_name}':")
try:
for blob in container_client.list_blobs():
print(blob.name)
except Exception as e:
print(f"Error listing blobs: {e}")
Output:
Hope this answer helps! please let us know if you have any further queries. I’m happy to assist you further.
Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.