如何使用Azure Storage SDK for Python读取Blob的内容?

问题描述 投票:0回答:1

我已将Azure软件包添加到我的Anaconda发行版中,还安装了Azure Storage SDK for Python。我正在尝试使用以下方法读取已上传到特定blob容器的文件:

from azure.storage import BlobService
blob_service = BlobService(account_name='azure subscription name',   
account_key='azure subscription key')

blobs = []
marker = None
while True:
   batch = blob_service.list_blobs('vrc', marker=marker, prefix='VRC_')
  blobs.extend(batch)
  if not batch.next_marker:
    break
  marker = batch.next_marker
for blob in blobs:
print(blob.name)

当我运行此脚本时,我收到以下错误:

ImportError: No module named 'azure.storage'

如何解决此问题,以便我可以读取blob容器中的文本文件和PDF?

python azure azure-storage-blobs azure-sdk-python
1个回答
1
投票

不太确定你如何安装存储sdk,或者你正在使用什么版本,但你应该只需要执行以下操作:

安装:

pip install azure-storage

导入和实例化blob服务:

from azure.storage.blob import BlockBlobService
blob_service = BlockBlobService(account_name="<storagename>",account_key="<storagekey>")

此时,您应该能够列出blob(或下载blob,或者您需要做的任何其他事情)。

© www.soinside.com 2019 - 2024. All rights reserved.