我正在尝试使用requests.get(url,auth =(username,password)从url获取数据,但是,请求中给定的数据与我尝试解析的实际XML文件数据不同< / p>
req = requests.get(url, auth=(username,password))
print(req.content)
输出:
{"node-connector":[{"id":"openflow:1:1","flow-node-inventory:peer-features":"","flow-node-inventory:hardware-address":"16:7a:37:db:ea:37","flow-node-inventory:port-number":1,"flow-node-inventory:current-feature":"ten-gb-fd copper","flow-node-inventory:supported":"","flow-node-inventory:advertised-features":"","flow-node-inventory:state":{"blocked":false,"live":false,"link-down":false},"flow-node-inventory:name":"s1-eth1","flow-node-inventory:configuration":"","opendaylight-port-statistics:flow-capable-node-connector-statistics":{"transmit-drops":0,"receive-frame-error":0,"receive-drops":0,"receive-crc-error":0,"bytes":{"transmitted":359195,"received":3360},"duration":{},"receive-errors":0,"transmit-errors":0,"receive-over-run-error":0,"collision-count":0,"packets":{"transmitted":1985,"received":48}},"address-tracker:addresses":[{"id":0,"ip":"10.0.0.1","mac":"36:3c:6c:9d:67:d8","first-seen":1552937366417,"last-seen":1552940142003}]}]}
已知的XML数据:
<node-connector xmlns="urn:opendaylight:inventory">
<id>openflow:1:1</id>
<peer-features xmlns="urn:opendaylight:flow:inventory"/>
<hardware-address
xmlns="urn:opendaylight:flow:inventory">16:7a:37:db:ea:37</hardware-address>
<port-number xmlns="urn:opendaylight:flow:inventory">1</port-number>
...
由于此内容输出,我无法使用lxml对其进行解析,我的GET是否缺少一些基本的内容?这是Linux还是python的怪癖(当我直接下载文件时,一切正常)?