英文:
MicrosoftResourceHealth azure.core.exceptions.DeserializationError exception
问题
问题是示例代码引发异常。
import json
from azure.identity import AzureCliCredential, DefaultAzureCredential
from azure.mgmt.resourcehealth import MicrosoftResourceHealth
# https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/resourcehealth/azure-mgmt-resourcehealth
def main():
resourcehealth_client = MicrosoftResourceHealth(
credential=AzureCliCredential(),
subscription_id='xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
)
emerging_events_list = list(resourcehealth_client.emerging_issues.list())
print(f"There are {len(emerging_events_list)} emerging issues items")
if __name__ == "__main__":
main()
异常:
azure.core.exceptions.DeserializationError: (', ValueError: Invalid datetime string: 2023-02-23 11:23:39Z', 'Cannot deserialize datetime object.', ValueError('Invalid datetime string: 2023-02-23 11:23:39Z'))
而其他操作是成功的,例如:
availability_statuses_list = list(resourcehealth_client.availability_statuses.list_by_subscription_id())
如何从新出现的问题中获取数据?
谢谢。
英文:
Problem is that sample code raises exception.
import json
from azure.identity import AzureCliCredential,DefaultAzureCredential
from azure.mgmt.resourcehealth import MicrosoftResourceHealth
#https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/resourcehealth/azure-mgmt-resourcehealth
def main():
resourcehealth_client = MicrosoftResourceHealth(
credential=AzureCliCredential(),
subscription_id = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
)
emerging_events_list = list(resourcehealth_client.emerging_issues.list())
print(f"There are {len(emerging_events_list)} emerging issues items")
if __name__ == "__main__":
main()
Exception;
azure.core.exceptions.DeserializationError: (', ValueError: Invalid datetime string: 2023-02-23 11:23:39Z', 'Cannot deserialize datetime object.', ValueError('Invalid datetime string: 2023-02-23 11:23:39Z'))
Whereas other operations are successful, e.g.
availability_statuses_list = list(resourcehealth_client.availability_statuses.list_by_subscription_id())
How is it possible to return data from emerging issues?
Thanks
答案1
得分: 0
我在我的环境中尝试并获得以下结果:
最初,在我的环境中出现了相同的错误。
> azure.core.exceptions.DeserializationError: (',反序列化错误: (',DeserializationError: (‘,ValueError: 无效的日期时间字符串: 2023-02-25 06:15:04Z',‘无法反序列化日期时间对象。',ValueError('无效的日期时间字符串: 2023-02-25 06:15:04Z'))",'无法反序列化响应数据。数据: 2023-02-25 06:15:04Z,iso-8601'
上述错误表明,Azure SDK for Python由于无效的日期时间字符串而无法反序列化来自Microsoft Resource-health API的响应。
响应中的日期时间字符串'2023-02-25 06:45:45Z
'似乎处于无效格式,导致反序列化错误。实际上,Python的格式应该是**2023-02-25 06:45:45
**,据我所知,这是由于Azure Python SDK的问题。
作为一种解决方法,您可以使用此Ms-Docs使用图形资源管理器通过REST API列出紧急问题:
命令:
GET https://management.azure.com/providers/Microsoft.ResourceHealth/emergingIssues?api-version=2018-07-01
响应:
{
"value": [
{
"id": "/providers/Microsoft.ResourceHealth/emergingissues/default",
"type": "/providers/Microsoft.ResourceHealth/emergingissues",
"name": "default",
"properties": {
"refreshTimestamp": "2023-02-25 07:14:19Z",
"statusBanners": [],
"statusActiveEvents": []
}
}
]
}
Postman:
英文:
I tried in my environment and got below results:
Initially, I got an same error in my environment.
> azure.core.exceptions.DeserializationError: (', DeserializationError: (", DeserializationError: (', ValueError: Invalid datetime string:2023-02-25 06:15:04Z', 'Cannot deserialize datetime object.', ValueError('Invalid datetime string: 2023-02-25 06:15:04Z'))",'Unable to deserialize response data. Data: 2023-02-25 06:15:04Z, iso-8601'
The above error indicates that the Azure SDK for Python is unable to deserialize a response from the Microsoft Resource-health API due to an invalid datetime string.
The datetime string '2023-02-25 06:45:45Z
' in the response appears to be in an invalid format, which is causing the deserialization error. Actually python format should be 2023-02-25 06:45:45
AFAIK, this is due to Azure python SDK issue.
As a workaround, you can use this Ms-Docs to list the emergency issues with REST API using graph explorer:
Command:
GET https://management.azure.com/providers/Microsoft.ResourceHealth/emergingIssues?api-version=2018-07-01
Response:
{
"value": [
{
"id": "/providers/Microsoft.ResourceHealth/emergingissues/default",
"type": "/providers/Microsoft.ResourceHealth/emergingissues",
"name": "default",
"properties": {
"refreshTimestamp": "2023-02-25 07:14:19Z",
"statusBanners": [],
"statusActiveEvents": []
}
}
]
}
Postman:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论