首页 > 解决方案 > 如何使用 Python 验证来自 json 响应的状态代码?

问题描述

我正在尝试使用 python 验证来自 json 响应的状态代码。在我正在使用的代码下方

import requests 
import json


  
# api-endpoint 
URL = "end pont url"
  
# sending get request and saving the response as response object 
r = requests.get(url = URL)
  
# extracting data in string format 
data = r.text

# converting string to json object
#res = json.loads(data)
response = json.loads(data)

print(response)


回复

{'Mac_address': '10:11.2', 'Response': {'parameters': [{'name': 'Device.info', 'message': 'Success'}], 'statusCode': 200}}

我需要从上述响应中验证状态码200成功消息。如何使用 python 提取和验证?

标签: python

解决方案


推荐阅读