{"record":{"id":"ab2479fc7e4ca183","repo":"HumanSignal/label-studio","slug":"azure-account-name-and-key-must-be-set-using-envir","errorCode":null,"errorMessage":"Azure account name and key must be set using environment variables AZURE_BLOB_ACCOUNT_NAME and AZURE_BLOB_ACCOUNT_KEY or account_name and account_key fields.","messagePattern":"Azure account name and key must be set using environment variables AZURE_BLOB_ACCOUNT_NAME and AZURE_BLOB_ACCOUNT_KEY or account_name and account_key fields\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"label_studio/io_storages/azure_blob/models.py","lineNumber":62,"sourceCode":"        _('regex_filter'), null=True, blank=True, help_text='Cloud storage regex for filtering objects'\n    )\n    use_blob_urls = models.BooleanField(\n        _('use_blob_urls'), default=False, help_text='Interpret objects as BLOBs and generate URLs'\n    )\n    account_name = models.TextField(_('account_name'), null=True, blank=True, help_text='Azure Blob account name')\n    account_key = models.TextField(_('account_key'), null=True, blank=True, help_text='Azure Blob account key')\n\n    def get_account_name(self):\n        return str(self.account_name) if self.account_name else get_env('AZURE_BLOB_ACCOUNT_NAME')\n\n    def get_account_key(self):\n        return str(self.account_key) if self.account_key else get_env('AZURE_BLOB_ACCOUNT_KEY')\n\n    def get_client_and_container(self):\n        account_name = self.get_account_name()\n        account_key = self.get_account_key()\n        if not account_name or not account_key:\n            raise ValueError(\n                'Azure account name and key must be set using '\n                'environment variables AZURE_BLOB_ACCOUNT_NAME and AZURE_BLOB_ACCOUNT_KEY '\n                'or account_name and account_key fields.'\n            )\n        connection_string = (\n            'DefaultEndpointsProtocol=https;AccountName='\n            + account_name\n            + ';AccountKey='\n            + account_key\n            + ';EndpointSuffix=core.windows.net'\n        )\n        client = BlobServiceClient.from_connection_string(conn_str=connection_string)\n        container = client.get_container_client(str(self.container))\n        return client, container\n\n    def get_container(self):\n        _, container = self.get_client_and_container()\n        return container","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/HumanSignal/label-studio/blob/0b49e9b53917880baf1dd85d574fe5541a9aafb2/label_studio/io_storages/azure_blob/models.py#L44-L80","documentation":"AzureBlobStorage.get_client_and_container requires an account name and account key from model fields or AZURE_BLOB_ACCOUNT_NAME/AZURE_BLOB_ACCOUNT_KEY env vars; if either resolves to None/empty it raises ValueError. Without both, an Azure Blob service client cannot be built.","triggerScenarios":"Creating/validating an Azure Blob import or export storage where account_name and account_key fields are empty AND the environment variables are unset — e.g. validate_connection, get_container, or get_bytes_stream calls.","commonSituations":"Running Label Studio in Docker/K8s without passing the env vars; using connection-string auth mindset when the code expects name+key; key rotated and cleared in DB; saving storage via UI without credentials, assuming env fallback that isn't configured on the server.","solutions":["Set AZURE_BLOB_ACCOUNT_NAME and AZURE_BLOB_ACCOUNT_KEY in the Label Studio environment and restart","Or supply account_name and account_key fields on the storage record (UI/API)","Verify env vars are actually visible to the process (docker exec env / kubectl exec env)","Confirm the values are non-empty — get_env returns None for missing/empty"],"exampleFix":"// before\nPOST /api/storages/azure/ {\"container\": \"docs\", \"prefix\": \"data\"}  → ValueError (no creds)\n// after\nexport AZURE_BLOB_ACCOUNT_NAME=mystorageacct\nexport AZURE_BLOB_ACCOUNT_KEY=<base64-key>\nPOST /api/storages/azure/ {\"container\": \"docs\", \"prefix\": \"data\"}  → 201","handlingStrategy":"validation","validationCode":"import os\nassert os.environ.get(\"AZURE_BLOB_ACCOUNT_NAME\"), \"AZURE_BLOB_ACCOUNT_NAME not set\"\nassert os.environ.get(\"AZURE_BLOB_ACCOUNT_KEY\"), \"AZURE_BLOB_ACCOUNT_KEY not set\"","typeGuard":"def azure_creds_present(account_name=None, account_key=None):\n    return bool((account_name or os.environ.get(\"AZURE_BLOB_ACCOUNT_NAME\")) and\n                (account_key or os.environ.get(\"AZURE_BLOB_ACCOUNT_KEY\")))","tryCatchPattern":"try:\n    resp = requests.post(f\"{LS_URL}/api/storages/azure/\", json=payload, headers=headers)\n    resp.raise_for_status()\nexcept (ValueError, requests.HTTPError) as e:\n    if \"AZURE_BLOB_ACCOUNT\" in str(e):\n        logging.error(\"Set AZURE_BLOB_ACCOUNT_NAME/AZURE_BLOB_ACCOUNT_KEY env vars or account fields\")","preventionTips":["Set both env vars in deployment config (Docker env, K8s Secret)","Verify with `docker exec <ctr> env | grep AZURE`","Either supply fields in the payload or env vars — not neither","Document credential requirements for self-hosted installs"],"tags":["azure","configuration","env-vars","credentials","storage"],"backgroundTag":"missing-env-var","analyzedSha":"0b49e9b53917880baf1dd85d574fe5541a9aafb2","analyzedAt":"2026-08-29T00:39:52.578Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}