Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Azure Storage SDK for Python读取blob的内容?_Python_Azure_Azure Storage Blobs_Azure Sdk Python - Fatal编程技术网

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

如何使用Azure Storage SDK for Python读取blob的内容?,python,azure,azure-storage-blobs,azure-sdk-python,Python,Azure,Azure Storage Blobs,Azure Sdk Python,我已经将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 = []

我已经将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?

不太确定您是如何安装storage sdk的,或者您使用的是什么版本,但您只需要执行以下操作:

安装:

pip install azure-storage
导入并实例化blob服务:

from azure.storage.blob import BlockBlobService
blob_service = BlockBlobService(account_name="<storagename>",account_key="<storagekey>")
从azure.storage.blob导入BlockBlobbService
blob\u服务=BlockBlob服务(账户名称=,账户密钥=)

此时,您应该能够列出BLOB(或下载BLOB,或您需要执行的任何其他操作)。

这是一个老问题,但由于SDK中某些代码块的最新弃用而变得相关

请按照下面的步骤获取给定容器中的blob文件列表,并附上修改日期

from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient
storageconnectionstring='yourstorageconnectionstring'
blobclient=BlobServiceClient.from_connection_string(storageconnectionstring)
containerclient=blobclient.get_container_client('yourblobcontainername')
for blobs in containerclient.list_blobs():
    print (blobs['name'],": Modified: ",blobs['last_modified'])

我在命令行使用git从Github下载了存储SDK。然后我运行了pip安装azure存储。我尝试使用Anaconda安装它,但该软件包不可用,只有Azure软件包。
Azure存储
需要加密。如果您使用的是linux,您还需要这样做:我们如何读取blob的内容?像文件流吗?@RamMehta-这是一个完全不同的问题。我建议发布一个新问题,以及您遇到的具体问题。