HumanSignal/label-studio · error · ValueError
Azure account name and key must be set using environment var
Error message
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.
What it means
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.
Source
Thrown at label_studio/io_storages/azure_blob/models.py:62
_('regex_filter'), null=True, blank=True, help_text='Cloud storage regex for filtering objects'
)
use_blob_urls = models.BooleanField(
_('use_blob_urls'), default=False, help_text='Interpret objects as BLOBs and generate URLs'
)
account_name = models.TextField(_('account_name'), null=True, blank=True, help_text='Azure Blob account name')
account_key = models.TextField(_('account_key'), null=True, blank=True, help_text='Azure Blob account key')
def get_account_name(self):
return str(self.account_name) if self.account_name else get_env('AZURE_BLOB_ACCOUNT_NAME')
def get_account_key(self):
return str(self.account_key) if self.account_key else get_env('AZURE_BLOB_ACCOUNT_KEY')
def get_client_and_container(self):
account_name = self.get_account_name()
account_key = self.get_account_key()
if not account_name or not account_key:
raise ValueError(
'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.'
)
connection_string = (
'DefaultEndpointsProtocol=https;AccountName='
+ account_name
+ ';AccountKey='
+ account_key
+ ';EndpointSuffix=core.windows.net'
)
client = BlobServiceClient.from_connection_string(conn_str=connection_string)
container = client.get_container_client(str(self.container))
return client, container
def get_container(self):
_, container = self.get_client_and_container()
return containerView on GitHub (pinned to 0b49e9b539)
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
Example fix
// before
POST /api/storages/azure/ {"container": "docs", "prefix": "data"} → ValueError (no creds)
// after
export AZURE_BLOB_ACCOUNT_NAME=mystorageacct
export AZURE_BLOB_ACCOUNT_KEY=<base64-key>
POST /api/storages/azure/ {"container": "docs", "prefix": "data"} → 201 Defensive patterns
Strategy: validation
Validate before calling
import os
assert os.environ.get("AZURE_BLOB_ACCOUNT_NAME"), "AZURE_BLOB_ACCOUNT_NAME not set"
assert os.environ.get("AZURE_BLOB_ACCOUNT_KEY"), "AZURE_BLOB_ACCOUNT_KEY not set" Type guard
def azure_creds_present(account_name=None, account_key=None):
return bool((account_name or os.environ.get("AZURE_BLOB_ACCOUNT_NAME")) and
(account_key or os.environ.get("AZURE_BLOB_ACCOUNT_KEY"))) Try / catch
try:
resp = requests.post(f"{LS_URL}/api/storages/azure/", json=payload, headers=headers)
resp.raise_for_status()
except (ValueError, requests.HTTPError) as e:
if "AZURE_BLOB_ACCOUNT" in str(e):
logging.error("Set AZURE_BLOB_ACCOUNT_NAME/AZURE_BLOB_ACCOUNT_KEY env vars or account fields") Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.
Related errors
- Azure account name and key must be set using environment var
- "form_layout.yml" is not found for {self.__class__.__name__}
- {connection validation error}
- Google Application Credentials must be valid JSON string. {e
- No blobs found in {bucket_name}/{prefix} or prefix doesn't e
AI-assisted analysis of HumanSignal/label-studio@0b49e9b539 (2026-08-29).
Data as JSON: /api/errors/ab2479fc7e4ca183.
Report an issue: GitHub.