Search code examples
azure-storageazure-sdk-python

Queue connect issue. QueueServiceClient.from_connection_string(conn_str=connect_str). The MAC signature... not the same as any computed signature


I am trying to follow the Microsoft queue quickstart that can be found here.

Since I get an error creating a queue, I am attempting to use this method:

connect_str = "<my connection string from portal>"
QueueServiceClient.from_connection_string(connect_str)

# List all queues in the storage account
all_queues = queue_service_client.list_queues()

I am using the connection string because my org does not use managed identities yet, so that is not an option.

Of course I really need to do "all the things" with queues but since that gave me trouble I tried just listing queues on that storage account, but to no avail. Same error whether trying to create one or list them.

Here is the error:

The MAC signature found in the HTTP request ... is not the same as any computed signature.

I have also tried using the API using the key and encoding the time but I get the same response. I used BingChat to search for similar issues. It found several "here" and other places, but none of them relate.

I know that my connection string is correct because I use it to access (read/write) specific BLOBs with no problem using the BLOB client.

I can access queues I know exist using the Azure CLI.

I first tried with an 11.7.x version of the SDK. Updating to 12.0.0 did not change the result.

  1. I think it may be a bug but decided to start here. My impression is that to use the connection string method, I should not need to be authenticated. Is that correct?

  2. I could try authenticating with the VSC sign-in but I believe I will need the connection string approach once I deploy to Azure. Is that correct?


Solution

  • RequestId:5fc43cc9-9003-0074-7696-175ae6000000 Time:2023-11-15T07:39:35.9380493Z ErrorCode:AuthenticationFailed authenticationerrordetail:The MAC signature found in the HTTP request'Uxxxxx=' is not the same as any computed signature. Server used following string to sign: 'GET

    The above error occurs If the connection string or account key used to authenticate the request is wrong or has expired. ensure that the connection string and account key for your Azure Blob storage account are accurate. You can also try regenerating the account key and replacing it in the connection string.

    Connection string be:

    DefaultEndpointsProtocol=https;AccountName=venkat678;AccountKey=<Your-storage-account-key>;EndpointSuffix=core.windows.net
    

    When I tried with the same code with the correct connection string and using azure-storage-queue= 12.8.0 Python SDK.

    Code:

    from azure.storage.queue import QueueServiceClient
    
    connect_str="DefaultEndpointsProtocol=https;AccountName=venkat678;AccountKey=xxxxxx;EndpointSuffix=core.windows.net"
    try:
        print("Azure Queue storage - Python quickstart sample")
        
        # Create a QueueService object which will be used to create and manipulate the queue
        queue_service = QueueServiceClient.from_connection_string(conn_str=connect_str)
        # List all queues in the storage account
        queues = queue_service.list_queues()
        for queue in queues:
            print(queue.name)
    
    except Exception as ex:
        print('Exception:')
        print(ex)
    

    Output:

    Azure Queue storage - Python quickstart sample
    queue1
    queue2
    queue3
    

    enter image description here

    Reference:

    Azure Storage Queues client library for Python | Microsoft Learn

    Update:

    You can get the connection_string from the portal also:

    Storage account-> access key -> copy the connection string.

    enter image description here