HumanSignal/label-studio · error · KeyError

{self.url_scheme}://{self.container}/{self.prefix} not found

Error message

{self.url_scheme}://{self.container}/{self.prefix} not found.

What it means

After confirming the container exists, validate_connection checks that at least one blob exists under the configured prefix (import storages only); if list_blob_names yields nothing it raises KeyError('<scheme>://<container>/<prefix> not found.'). The storage is reachable but the prefix path is empty or wrong.

Source

Thrown at label_studio/io_storages/azure_blob/models.py:102

        client, container = self.get_client_and_container()

        try:
            container_properties = container.get_container_properties()
            logger.debug(f'Container exists: {container_properties.name}')
        except ResourceNotFoundError:
            raise KeyError(f'Container not found: {self.container}')

        # Check path existence for Import storages only
        if self.prefix and 'Export' not in self.__class__.__name__:
            logger.debug(f'Test connection to container {self.container} with prefix {self.prefix}')
            prefix = str(self.prefix)
            try:
                blob = next(container.list_blob_names(name_starts_with=prefix))
            except StopIteration:
                blob = None

            if not blob:
                raise KeyError(f'{self.url_scheme}://{self.container}/{self.prefix} not found.')

    def get_bytes_stream(self, uri, range_header=None):
        """Get file bytes from Azure Blob storage as a streaming object with metadata.

        Implements range request support similar to GCS and S3 implementations:
        - Accepts ``range_header`` in format ``bytes=start-end``
        - Uses Azure's download_blob with offset/length for efficient ranged access
        - Returns a tuple of (stream_with_iter_chunks, content_type, metadata_dict)

        Args:
            uri: The Azure URI of the file to retrieve
            range_header: Optional HTTP Range header to limit bytes

        Returns:
            Tuple of (streaming body with iter_chunks, content_type, metadata)
        """
        # Parse URI to get container and blob name
        parsed_uri = urlparse(uri, allow_fragments=False)

View on GitHub (pinned to 0b49e9b539)

Solutions

  1. Verify with 'az storage blob list --container-name <c> --prefix <p>' that blobs exist under the prefix
  2. Correct the prefix to match actual blob paths (watch trailing slash and case)
  3. Upload at least one blob under the prefix before validating
  4. Remove the prefix if you want to validate against the container root

Example fix

// before
{"container": "docs", "prefix": "Data/2024"}  // blobs are at data/2024/ → KeyError not found
// after
{"container": "docs", "prefix": "data/2024"}  → 200 valid
Defensive patterns

Strategy: validation

Validate before calling

from azure.storage.blob import BlobServiceClient
svc = BlobServiceClient(account_url=f"https://{acct}.blob.core.windows.net", credential=key)
blobs = list(svc.get_container_client(container).list_blob_names(name_starts_with=prefix))
assert blobs, f"No blobs under prefix '{prefix}' in container '{container}'"

Type guard

def prefix_has_blobs(svc, container, prefix):
    return next(svc.get_container_client(container).list_blob_names(name_starts_with=prefix), None) is not None

Try / catch

try:
    resp = requests.post(f"{LS_URL}/api/storages/azure/validate/", json=payload, headers=headers)
    resp.raise_for_status()
except requests.HTTPError as e:
    if "not found" in resp.text:
        logging.error("Fix prefix or upload blobs under %s", prefix)

Prevention

When it happens

Trigger: Creating/validating an Azure Blob import storage with a prefix that matches no blobs in the container — prefix typo, wrong nesting depth, or container genuinely empty under that path.

Common situations: Prefix 'data/' when files are at root (trailing-slash/nesting mismatch); files uploaded to a different container; case sensitivity ('Data/' vs 'data/'); syncing a container whose contents were moved to another account.

Related errors


AI-assisted analysis of HumanSignal/label-studio@0b49e9b539 (2026-08-29). Data as JSON: /api/errors/1a8951ff33a64dcb. Report an issue: GitHub.