Reputation: 281
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```
Upvotes: 2
Views: 8402
Reputation: 66
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
Upvotes: 5
Reputation: 281
As mentioned by @kopaczew, reverting the azure_storage_blob to 12.6.0 version fixed my issue. It does seem to be some sort of bug with the latest azure-storage-blob library. Unfortunately, the aforementioned issue is not limited to the create_container call. Answering my own question in case this helps someone else in a similar situation.
How I fixed my issue:
Removed my previous venv environment (reinstalling itself caused some issues when importing the azure library)
Created new venv
pip install azure-storage-bob==12.6.0
Upvotes: 1