AttributeError:' BlockBlobService'对象没有属性' create_block_blob_from_path'

时间:2016-02-26 13:50:26

标签: python azure azure-sdk-python

Accocrding this手册我应该使用这个代码:

from azure.storage.blob import ContentSettings
block_blob_service.create_block_blob_from_path(
    'mycontainer',
    'myblockblob',
    'sunset.png',
    content_settings=ContentSettings(content_type='image/png')
            )

但得到了这个错误:

AttributeError: 'BlockBlobService' object has no attribute 'create_block_blob_from_path'

git以及pip

尝试
pip install azure-storage

1 个答案:

答案 0 :(得分:1)

与最新的Python SDK相比,我认为该教程已过时。我不认为那里有create_block_blob_from_path - 我查看了sdk代码(here)。块blob和页面blob有单独的导入,方法为create_blob_from_path

通过简单的修正:

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

content_settings = ContentSettings(content_type = "image/png")
blob_service.create_blob_from_path("mycontainer","myblockblob","sunset.png",content_settings)