我正在查询REST API,我需要从下面的适配器输出中选择2个字段。我基本上需要从OUT_Detailed Description和OUT_Vendor Ticket Number中创建变量:
代码:
headers = {'content-type': 'application/json', 'Authentication-Token': authToken}
response = requests.post('http://dev.startschools.local:2031/baocdp/rest/process/:ITSM_Interface:IncidentManagement:QueryIncident/execute', headers=headers, data=json.dumps(get_query_inc_json()))
print(response.text)
json_format = json.loads(response)
Description = (json_format['OUT_Detailed Decription'])
Ref_Number = (json_format['OUT_Vendor Ticket Number'])
response.text printed输出:
[{"name":"OUT_HPD_CI","value":"001"},{"name":"OUT_Detailed Description","value":"Student needs a new card issued"},{"name":"OUT_Vendor Ticket Number","value":"INC0000019"}]
错误:
in loads
raise TypeError(f'the JSON object must be str, bytes or bytearray, '
TypeError: the JSON object must be str, bytes or bytearray, not Response
PS C:\Program Files\SB_Python\AD Extract>
我尝试了几种方法来从输出中获取OUT_Detailed Description和OUT_Vendor Ticket Number值,但都失败了。
2条答案
按热度按时间41ik7eoe1#
列表中有3个字典,首先获取列表中想要的字典,并获取“value”键的值。
如果你想要更好的东西,用这个:
dw1jzc5e2#
你有没有试过做
json_format = json.loads(response.content.decode('utf-8'))
来将你的响应转换成字符串?