Azurite for dev testing
Describe the bug There is no use of DEV_AZURE_BLOB_ENDPOINT ENV in the chainlit source code, the AZURE hostname is hardcoded.
To Reproduce Try to use the documentation tutorial for dev test with azurite.
Expected behavior Connection to the azurite dev docker image with no torubles.
Screenshots During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "/usr/lib/python3.10/asyncio/tasks.py", line 234, in __step result = coro.throw(exc) File "/home/dario/.local/lib/python3.10/site-packages/chainlit/data/utils.py", line 25, in wrapper return await method(self, *args, **kwargs) File "/home/dario/.local/lib/python3.10/site-packages/chainlit/data/chainlit_data_layer.py", line 183, in create_element await self.storage_client.upload_file( File "/home/dario/.local/lib/python3.10/site-packages/chainlit/data/storage_clients/azure_blob.py", line 82, in upload_file raise Exception(f"Failed to upload file to Azure Blob Storage: {e!s}") Exception: Failed to upload file to Azure Blob Storage: Cannot connect to host fjklsdjklkljfdkldjfkls90fjdsfsdfjkmnajksdkmqurtoi38262.blob.core.windows.net:443 ssl:default [Name or service not known] 2025-04-06 14:30:18 - Request URL: 'https://FJKLSDJKLkljfdkldjfkls90FJDSFSDFJKmnAJKSDKMQURTOI38262.blob.core.windows.net/cl-dolfs/threads/070f8030-81fa-447a-9c4c-7ede64a32db3/files/819b3a12-138a-453c-baad-c1ed55f9eea1' Request method: 'PUT' Request headers: 'Content-Length': '76959' 'x-ms-blob-type': 'REDACTED' 'x-ms-blob-content-type': 'REDACTED' 'x-ms-version': 'REDACTED' 'Content-Type': 'application/octet-stream' 'Accept': 'application/xml' 'User-Agent': 'azsdk-python-storage-blob/12.25.1 Python/3.10.12 (Linux-6.11.0-21-generic-x86_64-with-glibc2.35)' 'x-ms-date': 'REDACTED' 'x-ms-client-request-id': 'a9c77954-12f3-11f0-a796-c87f54c6548d' 'Authorization': 'REDACTED' A body is sent with the request 2025-04-06 14:30:18 - Task exception was never retrieved future: <Task finished name='Task-4333' coro=<ChainlitDataLayer.create_element() done, defined at /home/dario/.local/lib/python3.10/site-packages/chainlit/data/utils.py:10> exception=Exception('Failed to upload file to Azure Blob Storage: Cannot connect to host fjklsdjklkljfdkldjfkls90fjdsfsdfjkmnajksdkmqurtoi38262.blob.core.windows.net:443 ssl:default [Name or service not known]')> Traceback (most recent call last): File "/home/dario/.local/lib/python3.10/site-packages/aiohttp/connector.py", line 1365, in _create_direct_connection hosts = await self._resolve_host(host, port, traces=traces) File "/home/dario/.local/lib/python3.10/site-packages/aiohttp/connector.py", line 995, in _resolve_host return await asyncio.shield(resolved_host_task) File "/usr/lib/python3.10/asyncio/futures.py", line 285, in await yield self # This tells Task to wait for completion. File "/usr/lib/python3.10/asyncio/tasks.py", line 304, in __wakeup future.result() File "/usr/lib/python3.10/asyncio/futures.py", line 201, in result raise self._exception.with_traceback(self._exception_tb) File "/usr/lib/python3.10/asyncio/tasks.py", line 234, in __step result = coro.throw(exc) File "/home/dario/.local/lib/python3.10/site-packages/aiohttp/connector.py", line 1026, in _resolve_host_with_throttle addrs = await self._resolver.resolve(host, port, family=self._family) File "/home/dario/.local/lib/python3.10/site-packages/aiohttp/resolver.py", line 39, in resolve infos = await self._loop.getaddrinfo( File "/usr/lib/python3.10/asyncio/base_events.py", line 863, in getaddrinfo return await self.run_in_executor( File "/usr/lib/python3.10/asyncio/futures.py", line 285, in await yield self # This tells Task to wait for completion. File "/usr/lib/python3.10/asyncio/tasks.py", line 304, in __wakeup future.result() File "/usr/lib/python3.10/asyncio/futures.py", line 201, in result raise self._exception.with_traceback(self._exception_tb) File "/usr/lib/python3.10/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) File "/usr/lib/python3.10/socket.py", line 955, in getaddrinfo for res in _socket.getaddrinfo(host, port, family, type, proto, flags): socket.gaierror: [Errno -2] Name or service not known
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "/home/dario/.local/lib/python3.10/site-packages/azure/core/pipeline/transport/_aiohttp.py", line 305, in send result = await self.session.request( # type: ignore File "/home/dario/.local/lib/python3.10/site-packages/aiohttp/client.py", line 703, in _request conn = await self._connector.connect( File "/home/dario/.local/lib/python3.10/site-packages/aiohttp/connector.py", line 548, in connect proto = await self._create_connection(req, traces, timeout) File "/home/dario/.local/lib/python3.10/site-packages/aiohttp/connector.py", line 1056, in _create_connection _, proto = await self._create_direct_connection(req, traces, timeout) File "/home/dario/.local/lib/python3.10/site-packages/aiohttp/connector.py", line 1371, in _create_direct_connection raise ClientConnectorDNSError(req.connection_key, exc) from exc aiohttp.client_exceptions.ClientConnectorDNSError: Cannot connect to host fjklsdjklkljfdkldjfkls90fjdsfsdfjkmnajksdkmqurtoi38262.blob.core.windows.net:443 ssl:default [Name or service not known]
workarround:
#################################
# MONKEY PATCH AZURE DEV STORAGE
#################################
from chainlit.data.storage_clients.azure_blob import AzureBlobStorageClient
from azure.storage.blob.aio import BlobServiceClient as AsyncBlobServiceClient
from chainlit.logger import logger
original_init = AzureBlobStorageClient.__init__
def AzureBlobStorageClient_patched_init(self, container_name: str, storage_account: str, storage_key: str):
self.container_name = container_name
self.storage_account = storage_account
self.storage_key = storage_key
if os.environ.get("APP_AZURE_STORAGE_CONNECTION_STRING"):
connection_string = os.environ.get("APP_AZURE_STORAGE_CONNECTION_STRING")
logger.info("Using connection string from environment variable")
else:
connection_string = (
f"DefaultEndpointsProtocol=https;"
f"AccountName={storage_account};"
f"AccountKey={storage_key};"
f"EndpointSuffix=core.windows.net"
)
logger.info("Using connection string from parameters")
if connection_string:
self.service_client = AsyncBlobServiceClient.from_connection_string(
connection_string
)
self.container_client = self.service_client.get_container_client(
self.container_name
)
logger.info("AzureBlobStorageClient initialized")
AzureBlobStorageClient.__init__ = AzureBlobStorageClient_patched_init
This issue is stale because it has been open for 14 days with no activity.
This issue was closed because it has been inactive for 7 days since being marked as stale.
workarround:
################################# # MONKEY PATCH AZURE DEV STORAGE ################################# from chainlit.data.storage_clients.azure_blob import AzureBlobStorageClient from azure.storage.blob.aio import BlobServiceClient as AsyncBlobServiceClient from chainlit.logger import logger original_init = AzureBlobStorageClient.__init__ def AzureBlobStorageClient_patched_init(self, container_name: str, storage_account: str, storage_key: str): self.container_name = container_name self.storage_account = storage_account self.storage_key = storage_key if os.environ.get("APP_AZURE_STORAGE_CONNECTION_STRING"): connection_string = os.environ.get("APP_AZURE_STORAGE_CONNECTION_STRING") logger.info("Using connection string from environment variable") else: connection_string = ( f"DefaultEndpointsProtocol=https;" f"AccountName={storage_account};" f"AccountKey={storage_key};" f"EndpointSuffix=core.windows.net" ) logger.info("Using connection string from parameters") if connection_string: self.service_client = AsyncBlobServiceClient.from_connection_string( connection_string ) self.container_client = self.service_client.get_container_client( self.container_name ) logger.info("AzureBlobStorageClient initialized") AzureBlobStorageClient.__init__ = AzureBlobStorageClient_patched_init
Hello. How can this workaround be applied?