python - Azure Blob 存储错误:指定的资源不存在
问题描述
我正在尝试通过 REST API 在 Azure Blob 存储中上传文件。容器的访问级别设置为 - 容器(对容器和 bolb 的匿名读取访问)。
共享代码和响应以供参考-
filepath = "/home/meera/Downloads/download.pdf"
account_name = "account_name"
container_name = "container_name"
name = "doc.pdf"
sas_token = "sas_token"
with open(filepath, 'rb') as f:
file_content = f.read()
headers = { "Content-Type": "application/pdf; charset=UTF-8", "x-ms-blob-type": "BlockBlob" }
url = "https://"+ account_name+".blob.core.windows.net/"+container_name+"/"+name+sas_token
response = requests.put(url, headers=headers, data=file_content)
错误:<Response [404]> <Code>ResourceNotFound</Code><Message>The specified resource does not exist.
解决方案
当然,您的解决方案很棒,但我们总是在这样的代码中使用 python-sdk:
# [START upload_a_blob]
# Upload content to block blob
with open(SOURCE_FILE, "rb") as data:
blob_client.upload_blob(data, blob_type="BlockBlob")
# [END upload_a_blob]
# [START download_a_blob]
with open(DEST_FILE, "wb") as my_blob:
download_stream = blob_client.download_blob()
my_blob.write(download_stream.readall())
# [END download_a_blob]
使用 rest api 需要一些标头,请在此处查看:https ://docs.microsoft.com/en-us/rest/api/storageservices/put-blob
推荐阅读
- ios - 用户 XXXXXX 的开发人员门户中不提供配置文件“XXXXXX”
- reactjs - react-window 保存已删除行的状态
- r - 在 R 中清理列数据
- java - 使用方法参考了解编译时错误
- python - 如何在python中执行一种热编码
- python - python3中的动态命名列表
- python - 在 Windows 10 上未考虑 tkinter 按钮上的 activebackground 选项
- gradle - 将环境变量从 build.gradle 传递给自定义插件
- javascript - 使用 turbolink 以编程方式打开 Bootstrap 选项卡
- aws-glue - 将从 AWS Glue 目录创建 AWS Athena 表定义的实用程序,以便我可以添加 WITH SERDEPROPERTIES 部分