python - Unable to Upload csv into Azure Blob Storage with LocationParseError label empty or too long - Stack Overflow

Trying to load a dataframe as a csv into azure blob storage but getting the below error. I have had a l

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', 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"
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)

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', 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"
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)
Share Improve this question asked Mar 3 at 12:42 CGardenCGarden 3473 silver badges21 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Silly mistake, I needed to feed the blob name I wanted to create into .get_blob_client. And I didn't need to create blob_service_client = BlobServiceClient(client)

Amended code:

blob_name = "testCsv.csv"
blob_client = container.get_blob_client(blob_name)
blob_client.upload_blob(csv_bytes, overwrite=True)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745094018a4610863.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信