gpt4 book ai didi

python - 使用 Python SDK 创建 Azure 容器时出现“HTTP header 格式不正确”错误

转载 作者:行者123 更新时间:2023-12-02 23:12:49 25 4
gpt4 key购买 nike

我正在尝试使用 Python SDK 和以下代码创建 Azure blob 容器。我在响应中收到“ErrorCode:InvalidHeaderValue”。

我正在使用存储帐户的 Azure 门户的“访问 key ”部分中的“ConnectionString”。我不认为连接是问题,因为这条线工作正常 blob_service_client = BlobServiceClient.from_connection_string(connection_string)

我为此使用了干净的 venv,下面是库版本 azure 核心==1.10.0 azure 存储blob==12.7.1

import os
import yaml
from azure.storage.blob import ContainerClient, BlobServiceClient

def load_config():
dir_root = os.path.dirname(os.path.abspath(__file__))
with open (dir_root + "/config.yaml", "r") as yamlfile:
return yaml.load(yamlfile, Loader=yaml.FullLoader)

config = load_config()
connection_string = config['azure_storage_connectionstring']

blob_service_client = BlobServiceClient.from_connection_string(connection_string)
blob_service_client.create_container('testing')
Traceback (most recent call last):
File "/Users/anojshrestha/Documents/codes/gen2lake/project_azure/lib/python3.7/site-packages/azure/storage/blob/_container_client.py", line 292, in create_container
**kwargs)
File "/Users/anojshrestha/Documents/codes/gen2lake/project_azure/lib/python3.7/site-packages/azure/storage/blob/_generated/operations/_container_operations.py", line 134, in create
raise HttpResponseError(response=response, model=error)
azure.core.exceptions.HttpResponseError: Operation returned an invalid status 'The value for one of the HTTP headers is not in the correct format.'

During handling of the above exception, another exception occurred:
.......
azure.core.exceptions.HttpResponseError: The value for one of the HTTP headers is not in the correct format.
RequestId:5X-601e-XXXX00ab-5368-f0c05f000000
Time:2021-01-22T02:43:22.3983063Z
ErrorCode:InvalidHeaderValue
Error:None
HeaderName:x-ms-version
HeaderValue:2020-04-08```

最佳答案

您无需重新安装。您可以通过在实例化任何客户端时设置 api_version 变量来解决此问题。

例如:

blob = BlobServiceClient(
account_url="https://MY_BLOB_STORAGE.blob.core.windows.net",
credential="MY_PRIMARY_KEY",
api_version="2019-12-12", #or api_version='2020-02-10'
)

https://github.com/Azure/azure-sdk-for-python/issues/16193

关于python - 使用 Python SDK 创建 Azure 容器时出现“HTTP header 格式不正确”错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65838755/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com