简体   繁体   English

如果响应不是 json 格式,如何解析来自 python 请求方法的响应?

[英]How to parse a response from python requests method if the response is not in json format?

I am using Python request method for sending a Post API request.我正在使用 Python 请求方法来发送 Post API 请求。 The content of the response obtained is in the following format:得到的响应内容格式如下:

<RESPONSE>
<DATE></DATE>
<CODE></CODE>
</RESPONSE>

How to proceed in parsing the response if I want to get the code from the response?如果我想从响应中获取代码,如何继续解析响应?

This looks like XML;这看起来像 XML; parse it using an XML library?使用 XML 库解析它?

Depending on the situation, you could also ignore that it's XML and just pluck out the pieces that you need;视情况而定,您也可以忽略它是 XML 而只是拔出您需要的部分; this will be particularly useful if the response is not in fact valid XML, but risks summoning eldritch horrors .如果响应实际上不是有效的 XML,这将特别有用,但有召唤可怕的恐惧的风险。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM