I am using below code to create new file in azure file storage
url = 'https://%s.file.core.windows.net/%s/%s/%s' % (
acc_name, share_name, dir_name, new_file)
string = 'PUT\n\n0\n\n\n\n\n\n\n\nx-ms-date:%s\nx-ms-version:%s\nx-ms-type:file\nx-ms-content-length:2024\n/%s/%s/%s/%s' % (
ms_date, ms_version, acc_name, share_name, dir_name, new_file)
signature = generate_sign(string)
headers = {
'x-ms-version': ms_version,
'x-ms-date': ms_date,
'x-ms-type': 'file',
'x-ms-content-length': 2024,
'Authorization': 'SharedKey %s:%s' % (acc_name, signature)
}
result = requests.put(url, headers=headers)
But after execution getting error like signature not corrent.
The MAC signature found in the HTTP request 'xslgK6ohXHCAnk2PaJt+RupQZwT/y9fPl8RTFA807fw='
is not the same as any computed signature. Server used following string to sign
: 'PUT
0
x-ms-content-length:2024
x-ms-date:Tue, 09 Jun 2015 07:39:24 GMT
x-ms-type:file
x-ms-version:2014-02-14
/filetest/test1/testdir/createtestfile'.</AuthenticationErrorDetail></Error>
You need to carefully verify that your string for the signature is correct. It appears there is an extra newline between the
PUT
and the0
, for example (you insert two, the error message uses three). Tripplecheck your string against the documentation and the error message.It may be easier to pull some of those signature values out of the prepared request, for example:
I ignored the query parameters; that's easier done without the encoded URL.