通过azure自动化runbook连接azure blob存储的Python代码

2024-06-09 17:12:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我是python新手,尝试使用下面的代码通过azure automation runbook连接azure blob存储。但代码失败,出现以下错误。我正在使用Python3 runbook,已经导入了azure blob和azure core所需的所有模块并添加了python包。 如有任何帮助,我们将不胜感激。提前谢谢

错误:enter image description here

代码

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)

Tags: 代码namefromimportadded错误servicebatch
1条回答
网友
1楼 · 发布于 2024-06-09 17:12:52

如果您想在Azure runbook中使用python3管理Azure blob,我们需要导入包azure.storage.blob及其依赖项

比如说

  1. 手动下载软件包
pip3 download -d <output dir name> azure-storage-blob==12.8.0

2.导入这些包 enter image description here

3.运行手册

a.代码

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)

b.测试 enter image description here

相关问题 更多 >