[Python] Unable to Upload csv into Azure Blob Storage with LocationParseError label empty or...

Discussão em 'Python' iniciado por Stack, Março 3, 2025.

  1. Stack

    Stack Membro Participativo

    Trying to load a dataframe as a csv into azure blob storage but getting the below error. I have had a look online but can't see what I am doing wrong. Some advice would be much appreciated.


    'DefaultEndpointsProtocol=https;AccountName=test;AccountKey=Test==;EndpointSuffix=core.windows.net', label empty or too long
    ​

    from azure.storage.blob import ContainerClient
    from azure.storage.blob import BlobServiceClient

    client = "DefaultEndpointsProtocol=https;AccountName=test;AccountKey=Test==;EndpointSuffix=core.windows.net"
    container_name = "test"
    blob_name = "testCsv.csv"

    container = ContainerClient.from_connection_string(client, container_name)
    blob_service_client = BlobServiceClient(client)

    data = {
    "calories": [420, 380, 390],
    "duration": [50, 40, 45]
    }

    df = pd.DataFrame(data)

    csv_string = df.to_csv(encoding='utf-8', index=False, header=True)

    csv_bytes = str.encode(csv_string)

    blob_client = blob_service_client.get_blob_client(container=container_name, blob=blob_name)
    blob_client.upload_blob(csv_bytes, overwrite=True)

    Continue reading...

Compartilhe esta Página