Here is the code to get file from Azure Blob Storage:
import base64
import hmac
import hashlib
import datetime
import requests
storage_account='your account name'
file_path='the path of your file'
token='shared key of your account'
def _sign_string(key, string_to_sign):
key = base64.b64decode(key.encode('utf-8'))
string_to_sign = string_to_sign.encode('utf-8')
signed_hmac_sha256 = hmac.HMAC(key, string_to_sign, hashlib.sha256)
digest = signed_hmac_sha256.digest()
encoded_digest = base64.b64encode(digest).decode('utf-8')
return encoded_digest
now = datetime.datetime.utcnow().strftime('%a, %d %b %Y %H:%M:%S GMT')
url ='https://{account}.blob.core.windows.net/{path}'.format(account=storage_account,path=file_path)
version = '2009-09-19' ## you may change this based on the version you are using
headers = {'x-ms-version': version,'x-ms-date': now}
content = 'GET{spaces}x-ms-date:{now}\nx-ms-version:{version}\n/{account}/{path}'.form
at(spaces='\n'*12,now=now, version=version, account=storage_account, path=file_path)
headers['Authorization'] = 'SharedKey ' + storage_account + ':' + _sign_string(token,
content)
response = requests.get(url, headers=headers)
assert response.status_code == 200
file = open("oci_servers.csv", "w")
file.write(response.text)
file.close()
#print response.text