当我在postman中向这个api发送post请求时,我得到了对post请求的响应输出。我只是想知道如何将其打印到屏幕上和/或解析以使用响应供进一步使用
url = ("https://mysupersecretapi/123456/execute")
headers = {'Accept': 'application/json', 'Accept-Encoding': 'gzip, deflate', 'Authorization': 'basic' , 'Content-Type':'application/json;charset=utf-8'}
perameters = {
"inputs": {
"Container_Full": 'true',
"Container_Note": "",
"Output_Stream_Id": "1",
"Piece_Serialized": "<Container><Pieces><PieceSerialNo>"+strContainer[0]+"</PieceSerialNo> <CustomerSerialNo/><Note></Note></Pieces></Container> ",
"Qty_Is_Container_Qty": 'true',
"Quantity": 1,
"Workcenter_Key": 58368,
"Validate_Only": 'false',
"Start_New_Container": 'true'
}
}
plexReq = requests.post(url,auth=HTTPBasicAuth, headers=headers, json=perameters)
print(plexReq.request.headers)
####START HERE
print(plexReq.status_code)
response = requests.get(url)
plexResponse = json.dumps(response.json)
print(plexResponse)
'''
这是我使用POSTMAN时得到的输出
{
"outputs": {
"New_Container": null,
"New_Serial_No": null,
"Recorded_Master_Unit_No": null,
"Recorded_Part_No": null,
"Recorded_Quantity": null,
"Recorded_Revision": null,
"Recorded_Serial_No": null,
"Result_Code": 5106,
"Result_Error": true,
"Result_Message": "Workcenter status does not allow production",
"Validation_Failed": false
},
"tables": [],
"transactionNo": "2069710"
}
'''
不知道你所说的
Printing to the screen?
是什么意思。PostMan只是一个用于发出API
请求的API工具,而不是一个能够将其打印到屏幕上的Python解释器到
parse it to use the response for further use
?无法解析提取的数据以用于另一个请求。只能在请求URL中手动执行编辑: 这只适用于邮递员,如果您的请求来自您的应用程序,则可以解决此问题,请参见here
相关问题 更多 >
编程相关推荐