Reputation: 5
I am trying to upload a blob using Jupyter Notebook to Azure Storage. I have a sample code as below:
from azure.storage.blob import BlockBlobService
accountName = "< account name>"
ContainerSAS = "<SAS key>"
containerName = "< container name>"
try:
sas_service = BlockBlobService(account_name=accountName, sas_token=ContainerSAS)
except Exception as e:
print("There was an error during SAS service creation. Details: {0}".format(e))
from azure.storage.blob import ContentSettings
blobName = "< blob name >"
try:
sas_service.create_blob_from_path(
'accountName',
'blobName',
'Chicago_Crime_Data-v2.csv',
content_settings=ContentSettings(content_type='Chicago_Crime_Data-v2/csv')
)
except Exception as e:
print("There was an error during blob uploading. Details: {0}".format(e))
But I am getting an error which says: Details: Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
I am not able to understand what is wrong here. I am a newbie. Any help would be really appreciated. Thanks.
Edit: Should I provide the account name, container name and key?
Upvotes: 0
Views: 4790
Reputation: 1245
My local file path was "./rootfolder" and then when it found a file to upload, it would be like file="./rootfolder/folder/file.dcm"
so then I tried to upload that file wholesale:
blob_client = blob_service_client.get_blob_client(container=container_name, blob=file)
And then I got the following error:
Azure Server failed to authenticate the request
and
AuthenticationErrorDetail:The MAC signature found in the HTTP request '' is not the same as any computed signature. Server used following string to sign: 'PUT...
I found you had to something like this instead, to remove that ./
from the file path.
file_path_on_azure = file_name.replace("./", "")
blob_client = blob_service_client.get_blob_client(container=container_name, blob=file_path_on_azure)
Upvotes: 3
Reputation: 30025
Please make sure you generate the sas token as per this screenshot:
There is also an error in the sas_service.create_blob_from_path
method, the first parameter should be container_name
, not account_name
The following code works well at my side:
from azure.storage.blob import BlockBlobService, ContentSettings
accountName = "xxx"
ContainerSAS = "xxx"
containerName = "test4"
sas_service = BlockBlobService(account_name=accountName,sas_token=ContainerSAS)
blobname = "222.PNG"
sas_service.create_blob_from_path(containerName,blobname,"F:\\azure stack overflow\\2019\\09\\30\\disk.PNG")
print("done")
Test result:
Upvotes: 1
Reputation: 1930
Kindly verify whether your account Key is right and also ensure that your system time is set correctly , If your system time is set incorrect you might get "Failed to Authenticate" error.
Upvotes: 0