I have a (private) blob in Azure blob storage that was written through an account that has write and read access to it (it was written through this account by terraform). I am trying to fetch it through Python (without Azure SDK) and I have been unable to.
My request is as follows:
import datetime
import requests
key = ...
secret = ...
now = datetime.datetime.utcnow().strftime('%a, %d %b %Y %H:%M:%S GMT')
# the required settings, as per https://docs.microsoft.com/en-us/rest/api/storageservices/get-blob
headers = {'Authorization': 'SharedKey {}:{}'.format(key, secret),
'Date': now,
'x-ms-version': '2018-03-28'
}
storage_account = ...
container = ...
url = 'https://{}.blob.core.windows.net/{}/terraform.tfstate'.format(storage_account, container)
response = requests.get(url, headers=headers)
print(response.status_code)
print(response.text)
This yields
400
<?xml version="1.0" encoding="utf-8"?><Error>
<Code>OutOfRangeInput</Code><Message>One of the request inputs is out of range.
RequestId:...
Time:...</Message></Error>
I have validated that this file exists (Storage explorer) and that, when I access it via the console, I get the same URL as the one above, but with extra GET parameters.
For those wondering: the reason I decided not to use Azure SDK for Python: I only need to get a blob and pip install azure[blob]
would add 88 dependencies to the project (IMO unacceptably high number for such a simple task).