python - Python 请求 xml: xml.parsers.expat.ExpatError: not well-formed (invalid token):
问题描述
我在使用 xmltodict 解析 XML 时遇到问题。此方法适用于其他在线 XML 文件,但现在我收到此错误:“xml.parsers.expat.ExpatError: not well-formed (invalid token):”
这里出了什么问题,我该如何解决/解决它?
import requests
import xmltodict
metadataxml = "https://nedlasting.geonorge.no/geonorge/Tjenestefeed_daglig.xml"
md_response = requests.get(metadataxml, stream=True)
md_data = md_response.text
xml = xmltodict.parse(md_data)
解决方案
将 response.text 更改为 response.content 似乎可以解决问题。
metadataxml = "https://nedlasting.geonorge.no/geonorge/Tjenestefeed_daglig.xml"
md_response = requests.get(metadataxml, stream=True)
md_data = md_response.text
xml = xmltodict.parse(md_data)
推荐阅读
- war - 将常见的 jar 从 WAR 移动到 EAR
- go - 如何在不牺牲内存的情况下组织类似的结构以避免重复
- api - 如何从 Angular7 前端传递关于 API 识别的 CORS 问题?
- css - 小高度div中的大高度图像 Bootstrap 4
- css - Font-Awesome 5 - CSS 伪元素,如何镜像/旋转图标
- php - 从数组中删除值为 0 的项目(和键)
- python - 在python中找到切比雪夫多项式的根
- java - 由于 spring 安全性,无法访问 spring-boot 项目中的资产
- go - Cobra cli 无法初始化新工具
- asp.net-core - 不同项目中的 MiniProfiler