MicrosoftResourceHealth azure.core.exceptions.DeserializationError 异常

huangapple go评论80阅读模式
英文:

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:

MicrosoftResourceHealth azure.core.exceptions.DeserializationError 异常

英文:

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:

MicrosoftResourceHealth azure.core.exceptions.DeserializationError 异常

huangapple
  • 本文由 发表于 2023年2月23日 19:33:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/75544251.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定