Vitaly Belyasov
Vitaly Belyasov

Reputation: 51

Azure storage error using Python SDK

I've download Azure SDK for python to my Ubuntu (Tool version 0.8.16). And i'm trying to run this code

from azure.storage import BlobService
blob_service = BlobService(account_name='Real_Name', account_key='Real_Key')
blob_service.create_container('mycontainer')
blob_service.create_container('mycontainer', x_ms_blob_public_access='container') 

blob_service.put_block_blob_from_path(
    'mycontainer',
    'myblob',
    'sunset.png',
    x_ms_blob_content_type='image/png'
)

I've saved it under Test.py and i'm trying to run it with

python Test.py

in terminal and i get this error

Traceback (most recent call last):
  File "Test.py", line 3, in <module>
    blob_service.create_container('mycontainer')
  File "/home/parallels/azure-sdk-for-python/azure/storage/blobservice.py", line 203, in create_container
    _dont_fail_on_exist(ex)
  File "/home/parallels/azure-sdk-for-python/azure/__init__.py", line 525, in _dont_fail_on_exist
    raise error
azure.WindowsAzureError: Unknown error (Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.)
<?xml version="1.0" encoding="utf-8"?><Error><Code>AuthenticationFailed</Code><Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
RequestId:98ce37f9-0001-003f-350e-7d3666000000
Time:2015-03-24T10:07:00.3385327Z</Message><AuthenticationErrorDetail>Request date header too old: 'Tue, 24 Mar 2015 09:06:59 GMT'</AuthenticationErrorDetail></Error>

How to fix this, and am i do everything right?

Thanks

Upvotes: 5

Views: 5277

Answers (2)

cbare
cbare

Reputation: 12458

I get similar errors due to clock skew after resuming WSL 2 (Windows Subsystem for Linux) sessions from sleep then using the Azure cli from the bash/zsh command line. This fixes the clock:

sudo hwclock -s -v

See: Fixing clock skew with WSL 2

Update: This bug seems to be fixed in WSL kernel version 5.10.16.3-microsoft-standard-WSL2. After upgrading, I haven't seen it. See: https://github.com/microsoft/WSL/issues/5014#issuecomment-605243281

Upvotes: 10

Gaurav Mantri
Gaurav Mantri

Reputation: 136136

As mentioned in the error:

Request date header too old: 'Tue, 24 Mar 2015 09:06:59 GMT'

You will get this error if difference between the date/time on your computer (in UTC) and date/time on Azure Storage Server is more than 15-20 minutes (your computer's date/time is behind that of Azure).

UPDATE

Essentially what happens is that when a request is sent to Azure Storage Service (e.g. create container) the SDK takes the local date/time of your computer, converts it into UTC and then sends it to Azure along with the request (as a request header either date or x-ms-date). Upon receiving the request, among other things Azure Storage service compares this date/time with its date/time and if the difference is more than 15-20 minutes (your clock is behind), Azure Storage service throws the error you're getting. This is done as a security measure so that in case somebody got hold of your request can't replay the request over and over again.

Upvotes: 6

Related Questions