如何解决通过 azure 自动化运行手册连接 azure blob 存储的 Python 代码
我是 python 新手,并尝试使用以下代码通过 azure 自动化运行手册连接 azure blob 存储。但代码失败并出现以下错误。我正在使用 python 3 runbook,并为 azure blob 和 azure core 添加了所有必需的模块和 python 包。 任何帮助将不胜感激。提前致谢
错误:
from azure.storage import *
from azure.storage.blob import BlobServiceClient
blob_service = BlobServiceClient(account_name='<added blob storage name>',account_key='<added blob storage key>')
blobs = []
marker = None
while True:
batch = blob_service_client.list_blobs('data',marker=marker)
blobs.extend(batch)
if not batch.next_marker:
break
marker = batch.next_marker
for blob in blobs:
print(blob.name)
解决方法
如果要在 Azure Runbook 中使用 python3 管理 Azure blob,我们需要导入包 azure.storage.blob
及其依赖项。
例如
- 手动下载软件包
pip3 download -d <output dir name> azure-storage-blob==12.8.0
3.操作手册
代码
from azure.storage.blob import BlobServiceClient
connect_str = ''
blob_service_client = BlobServiceClient.from_connection_string(connect_str)
container_client=blob_service_client.get_container_client('test')
blobs = container_client.list_blobs( )
for blob in blobs:
print(blob.name)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。