簡體   English   中英

Python 代碼通過 azure 自動化運行手冊連接 azure blob 存儲

[英]Python code to connect azure blob storage via azure automation runbook

我是 python 的新手,並嘗試使用以下代碼通過 azure 自動化運行手冊連接 azure blob 存儲。但代碼失敗並出現以下錯誤。 I am using python 3 runbook and have all the required modules imported and python package added for azure blob and azure core. 任何相同的幫助將不勝感激。 提前致謝

錯誤: 在此處輸入圖像描述

代碼

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)

If you want to manage Azure blob with python3 in Azure runbook, we need to import package azure.storage.blob with its dependencies.

例如

  1. 手動下載包
pip3 download -d <output dir name> azure-storage-blob==12.8.0

2.導入這些包在此處輸入圖像描述

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.測試在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM