AuthenticationFailedServer failed to authenticate the request

Qian Huang 0 Reputation points
2023-09-20T05:49:16.3266667+00:00

I use generate_file_sas to get a token for a file in Azure Blog Storage file shares. The code in python is as below

    def get_file_sas(cls, account_name, share_name, file_path, rights, minutes):

        # Create a SAS token that's valid for 30 minutes
        start_time = datetime.datetime.now(datetime.timezone.utc)
        expiry_time = start_time + datetime.timedelta(minutes=minutes)
        key = "q... =="
        sas_token = generate_file_sas(account_name=account_name,
            share_name=share_name,
            file_path=file_path, account_key = key,
            permission=rights, expiry=expiry_time)

        return sas_token

    ```

It always report error like: "

`AuthenticationFailed`Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. RequestId:8dfa9bd4-f01a-0032-487e-eb8051000000 Time:2023-09-20T04:53:10.5521004ZSignature did not match. String to sign used was r 2023-09-20T05:06:18Z /file/....png 2023-01-03"

in "/file/...png", I marked the detail file path.

I have checked:

1. Time on server, it's correct. I am using an Azure VM.

1. The key, it's the key value I copied from the Azure portal. The value looks like "q...g ==", with a few spaces in the string(meanwhile, there is no spaces in connection string)

1. No start time, only end time

Would anyone please help and advise? 

Azure Files
Azure Files
An Azure service that offers file shares in the cloud.
1,274 questions
Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
2,785 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Sumarigo-MSFT 45,776 Reputation points Microsoft Employee
    2023-09-22T07:39:55.4633333+00:00

    @Qian Huang Welcome to Microsoft Q&A Forum, Thank you for posting your query here!
    Based on the error message: AuthenticationFailedServer failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. RequestId:8dfa9bd4-f01a-0032-487e-eb8051000000 Time:2023-09-20T04:53:10.5521004ZSignature did not match. String to sign used was r 2023-09-20T05:06:18Z /file/....png 2023-01-03"

    Based on the error message you provided, it seems like there might be an issue with the SAS token that you're generating. Here are a few things you can try to resolve the issue:

    1. Double-check that the account_name, share_name, and file_path parameters that you're passing to the generate_file_sas function are correct and match the values in your Azure portal.
    2. Make sure that the permission parameter that you're passing to the generate_file_sas function is in the correct format. The permission parameter should be a string that specifies the permissions that you want to grant to the SAS token For example, if you want to grant read and write permissions, the permission parameter should be "rwd".

    User's image

    1. Check that the expiry_time parameter that you're passing to the generate_file_sas function is in the correct format. The expiry_time parameter should be a datetime object that specifies the time when the SAS token will expire.
    2. Verify that the key parameter that you're passing to the generate_file_sas function is correct and matches the storage account key in your Azure portal.

    Can you try to re-generate the SAS token through Azure Storage Explorer tool or generating a shared access signature (in azure portal) for key2 instead of key1. Changing the key fixed the error. (Settings > Shared access signature) Also the connection string should be updated as well - if used. (Settings > Access keys)and try again

    Also to upload or download files to an Azure Storage account, there are several option, Especially easy and the fastest ways is through Azcopy tool

    Authorize requests to Azure Storage

    Please let us know if you have any further queries. I’m happy to assist you further.     


    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.