如何解决无法从azure.storage.blob导入名称BlockBlobService
尽管有很多与我要问的问题类似的问题,但没有一个对我有帮助。
我正尝试使用python脚本直接通过系统将文件存储到我的Azure存储blob中。
这是我正在使用的脚本:
import os,uuid,sys
from azure.storage.blob import BlockBlobService,PublicAccess
def run_sample():
try:
block_blob_service = BlockBlobService(account_name=<acc-name>,account_key=<acc-key>)
# Create a file in Documents to test the upload and download.
local_path=os.path.abspath(os.path.curdir)
local_file_name =input("Enter file name to upload : ")
full_path_to_file =os.path.join(local_path,local_file_name)
print("Temp file = " + full_path_to_file)
print("\nUploading to Blob storage as blob" + local_file_name)
# Upload the created file,use local_file_name for the blob name
container_name ='handwritten-text'
block_blob_service.create_blob_from_path(container_name,local_file_name,full_path_to_file)
# List the blobs in the container
print("\nList blobs in the container")
generator = block_blob_service.list_blobs(container_name)
for blob in generator:
print("\t Blob name: " + blob.name)
except Exception as e:
print(e)
# Main method.
if __name__ == '__main__':
run_sample()
尽管,如果我正在运行脚本,则会收到以下错误消息:
ImportError: cannot import name 'BlockBlobService' from 'azure.storage.blob' (/home/nishant/anaconda3/envs/mera_env/lib/python3.7/site-packages/azure/storage/blob/__init__.py)
这是点冻结的结果:
azure-cognitiveservices-vision-computervision==0.6.0
azure-common==1.1.25
azure-core==1.8.0
azure-storage-blob==12.3.2
如何解决该问题?
解决方法
v12 sdk使用BlobServiceClient
代替BlockBlobService
,如果要使用BlockBlobService
,则应使用v2 sdk。有关v12 sdk的用法,请参阅此official doc。
因此,请将其更改为from azure.storage.blob import BlobServiceClient,PublicAccess
。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。