微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Azure python Runbook无法在门户中运行,但是从开发箱中成功执行了相同的代码

如何解决Azure python Runbook无法在门户中运行,但是从开发箱中成功执行了相同的代码

嗨,我面临一个奇怪的问题。我已经在Azure自动化帐户下创建了一个Azure python Runbook。目前,该代码正在尝试连接到存储帐户并获取所有容器。

这是代码

from azure.storage.blob import BlobServiceClient,BlobClient,ContainerClient

cred = r"?sas-token-xyz-xyz"
source_container_name = "sample"
account_url = "https://xyzxyzxyz.blob.core.windows.net"

blob_source_service_client = BlobServiceClient(account_url=account_url,credential=cred)
containers_list = blob_source_service_client.list_containers(include_Metadata=True)

for container in containers_list:
    print(container)

print("Done")

从我的dev框中执行此代码后,将得到如下所示的正确结果

$ python blob_runbook.py
{'name': 'sample','last_modified': datetime.datetime(2020,11,4,1,20,23,tzinfo=datetime.timezone.utc),'lease': {'status': 'unlocked','state': 'available','duration': None},'public_access': None,'has_immutability_policy': False,'deleted': None,'version': None,'has_legal_hold': False,'Metadata': {}}
Done

azure门户网站执行该命令时,出现以下错误。无法理解

Failed
Traceback (most recent call last):  File "C:\Temp\xqnsssxx.aun\daad1b3f-94be-4ea4-b4ef-6730a3282b53",line 10,in <module>    for container in containers_list:  File "C:\Python27\lib\site-packages\azure\core\paging.py",line 122,in __next__    return next(self._page_iterator)  File "C:\Python27\lib\site-packages\azure\core\paging.py",line 74,in __next__    self._response = self._get_next(self.continuation_token)  File "C:\Python27\lib\site-packages\azure\storage\blob\_models.py",line 399,in _get_next_cb    use_location=self.location_mode)  File "C:\Python27\lib\site-packages\azure\storage\blob\_generated\operations\_service_operations.py",line 341,in list_containers_segment    deserialized = self._deserialize('ListContaineRSSegmentResponse',response)  File "C:\Python27\lib\site-packages\msrest\serialization.py",line 988,in __call__    raise_with_traceback(DeserializationError,msg,err)  File "C:\Python27\lib\site-packages\msrest\exceptions.py",line 50,in raise_with_traceback    raise errormsrest.exceptions.DeserializationError: Unable to deserialize to object: type,AttributeError: 'RequestsTransportResponse' object has no attribute 'get'

寻找一些帮助。 谢谢

解决方法

我找到了一种解决方法,可以通过访问存储帐户类来访问容器中的blob。

from azure.common.credentials import UserPassCredentials
from azure.mgmt.resource import ResourceManagementClient
from azure.mgmt.storage import StorageManagementClient
from azure.storage import CloudStorageAccount
from azure.storage.blob.models import ContentSettings,PublicAccess


##Read data from storage account
sas = r"?sas-token-xyz-xyz"
account =  CloudStorageAccount(account_name='bunprdmelaasdata',sas_token=sas);
blobClient = account.create_block_blob_service()
containers = blobClient.list_containers();
for container in containers:
    print('Container Name: ' + container.name)

print("Done")

我想到BlobServiceClient的唯一原因不可用,我不得不下载并添加到自动化python打包程序中。但对于以上内容,我没有添加任何python软件包。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。