Azure/azure-sdk-for-python

Integration Error between azure-blob-storage container and Python Client

AlanTuring1988 opened this issue · 7 comments

I'm trying to integrate a python script with the mcr.microsoft.com/azure-blob-storage:latest docker module.

I get the same error both when I invoke both the container_client.exists() and container_client.create_container() methods

The sdk Python version used is azure-storage-blob==12.19.1

Error:

`

  Response status: 400
  Response headers:
      'x-ms-request-id': '87a60859-cb94-4596-8d26-0b8320e77bee'
      'Content-Type': 'application/xml'
      'Server': 'Microsoft-NetCore/2.0'
      'Date': 'Fri, 10 May 2024 14:44:41 GMT'
      'Content-Length': '940'
      'Connection': 'close'
  Response content:
  Exception:
  The value for one of the HTTP headers is not in the correct format.
  RequestId:87a60859-cb94-4596-8d26-0b8320e77bee
  Time:2024-05-10T14:44:41.7156917Z
  ErrorCode:InvalidHeaderValue
  headername:x-ms-version
  headervalue:2023-11-03
  exceptiondetails:None
  Content: <?xml version="1.0" encoding="utf-8"?><Error><Code>InvalidHeaderValue</Code><Message>The value for one of the HTTP headers is not in the correct format.
  RequestId:87a60859-cb94-4596-8d26-0b8320e77bee
  Time:2024-05-10T14:44:41.7156917Z</Message><HeaderName>x-ms-version</HeaderName><HeaderValue>2023-11-03</HeaderValue><ExceptionDetails><ExceptionMessage>The value 2023-11-03 provided for request header x-ms-version is invalid.</ExceptionMessage><StackTrace>Microsoft.Cis.Services.Nephos.Common.Protocols.Rest.InvalidHeaderProtocolException: The value 2023-11-03 provided for request header x-ms-version is invalid.
     at Microsoft.Cis.Services.Nephos.Common.Protocols.Rest.BasicHttpProcessorWithAuthAndAccountContainer`1.RunVersionCheck()
     at Microsoft.Cis.Services.Nephos.Common.Protocols.Rest.BasicHttpProcessorWithAuthAndAccountContainer`1.ProcessImpl(AsyncIteratorContext`1 async)+MoveNext()</StackTrace></ExceptionDetails></Error>

`

Code:
`

connection_string = f"DefaultEndpointsProtocol=http;BlobEndpoint=http://{params.localBlobStorageName}:11002/{params.accountName};AccountName={params.accountName};AccountKey={params.accountKey}";

logger = logging.getLogger('azure.storage.blob')
logger.setLevel(logging.DEBUG)

handler = logging.StreamHandler(stream=sys.stdout)
logger.addHandler(handler)
try:
    service = BlobServiceClient.from_connection_string(connection_string,logging_enable=True)

    container_name = "my_container_name"

    container_client = service.get_container_client(container=container_name)

    if not container_client.exists():
            container_client.create_container()

except Exception as ex:
    print('Exception:')
    print(ex)

`

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @jalauzon-msft @vincenttran-msft.

I tried with version 12.5.0 of the python sdk and the problem not exist. in fact I uploaded the blob locally and then check it on the cloud.

Hi @AlanTuring1988 - thanks for opening an issue. We'll take a look asap!

Hi @AlanTuring1988, the main reason for the behavior you are seeing is that that Docker image does not stay up to date with the Storage service in terms of API versions. In fact, it looks like it has not been updated in some time. That page says the last API version they added support for was 2020-04-08 which is quite old. I'm not sure if this image is deprecated or what is going on there. Perhaps they have added support for newer ones without specifying.

With each minor release of the SDK, we update the default API version that is used to the latest supported by the live Azure Storage service. For 12.19.1 that is 2023-11-03 which is what you are seeing in the error message. As mentioned, it seems that image may only support up to 2020-04-08.

So, you have two options:

  • You can downgrade your SDK version, like you have done (I am not quite sure what is the latest version you can use as we did not used to write the API version in the CHANGELOG but it seems like it will have to be before 12.9.0 at least).
  • You can try using the latest SDK but manually setting the API version in the client constructor using the api_version keyword. Anything in this list is valid but you may want to start with 2020-04-08 and work your way up.
    • There is a chance, depending on what operations and auth type you are using, that this does not work as changes in the SDK are not always backwards compatible with older API versions.

You can also try submitting feedback for that image here to see if there are plans to update it further or whether there is a replacement. (The SDK team is not familiar with it at all.)

Hi @AlanTuring1988. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text "/unresolve" to remove the "issue-addressed" label and continue the conversation.