【发布时间】:2019-06-03 02:52:17
【问题描述】:
我在 Azure blob 存储中有一个(私有)blob,它是通过一个对其具有读写访问权限的帐户写入的(它是由 terraform 通过此帐户写入的)。我正在尝试通过 Python(没有 Azure SDK)获取它,但我一直无法。
我的要求如下:
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)
这会产生
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>
我已验证此文件存在(存储资源管理器),并且当我通过控制台访问它时,我会得到与上述相同的 URL,但带有额外的 GET 参数。
对于那些想知道的人:我决定不使用 Azure SDK for Python 的原因是:我只需要获取一个 blob 和 pip install azure[blob] 就会向项目添加 88 依赖项(IMO 对这么简单的任务)。
【问题讨论】: