我正在尝试从我的存储帐户下载 Azure Blob 存储文件,为此,我已检查 URL 是什么,并且正在执行以下操作:
with urllib.request.urlopen("<url_file>") as resp:
img = np.asarray(bytearray(resp.read()), dtype="uint8")
但是我收到以下错误:
urllib.error.HTTPError: HTTP Error 404: The specified resource does not exist.
我已仔细检查该网址是否正确。这是否与未传递我的订阅 key 或有关存储帐户的任何其他信息有关?
有什么想法吗?
最佳答案
截至 2019 年 12 月 26 日,我无法从 Azure 云存储导入 BaseBlobService。 BlobPermissions、generate_blob_shared_access_signature 都不适合我。以下是我使用过的东西,它对我的情况有效,希望它有所帮助
from azure.storage.blob import generate_blob_sas, AccountSasPermissions
def scan_product():
account_name=<account_name>
container_name=<container_name>
blob_name=<blob_name>
account_key=<account_key>
url = f"https://{account_name}.blob.core.windows.net/{container_name}/{blob_name}"
sas_token = generate_blob_sas(
account_name=account_name,
account_key=account_key,
container_name=container_name,
blob_name=blob_name,
permission=AccountSasPermissions(read=True),
expiry=datetime.utcnow() + timedelta(hours=1)
)
url_with_sas = f"{url}?{sas_token}"
关于python - 如何在Python中通过URL下载Azure Blob存储文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56769671/