Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
246 views
in Technique[技术] by (71.8m points)

'HTTP headers is not in the correct format' error when creating Azure Container using Python SDK

I'm trying to create an Azure blob container using Python SDK with the below code. I'm getting an 'ErrorCode:InvalidHeaderValue' in the response.

I'm using the 'ConnectionString' from 'Access Keys' section from the Azure Portal of the storage account. And I don't think the connection is the issue since this line works ok blob_service_client = BlobServiceClient.from_connection_string(connection_string).

I used a clean venv for this and below are the library versions azure-core==1.10.0 azure-storage-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```
question from:https://stackoverflow.com/questions/65838755/http-headers-is-not-in-the-correct-format-error-when-creating-azure-container

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You do not need to reinstall. You can get around this issue by setting your api_version variable when instantiating any of the clients.

For example:

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...