defusedxml 导致 xml.etree.ElementTree.Element 异常

作者: , 共 938 字 , 共阅读 0

在升级 django-wiki 后, Python 的 markdown 库里爆出来一个错误:

SubElement() argument 1 must be xml.etree.ElementTree.Element, not Element

仔细看 markdown 库的源代码,没有查出任何问题。在 stackoverflow 上查到一个诡异的说法

ElementTree in its C version is very picky about the exact class that is being passed in. So that if the elements come from a file loading the python version of ElementTree, you can't insert them in your ElementTree. Even if they're both loading the C-version of ElementTree (cElementTree before Python 3.3), if they're not loading from the same binary file (one is inside the virtual environment, one is outside, for instance), then this message appears (formerly the even more cryptic argument 1 must be Element, not Element message).

但他也没说怎么解决。继续查找,发现 defusedxml 的一个问题defusedxml.ElementTree breaks the xml.etree.ElementTree package,尝试升级 defusedxml 库后,问题解决。

defusedxml 库用来解决 XML 的安全性问题( Python 自带的 xml.etree.ElementTree 模块对于恶意构建的数据是不安全的),没想到自己引入这么大的问题。

Q. E. D.

IT » nginx
在 nginx 里设置了一个转发:
户外 » 地图, 露营
中国探险协会和地理公社联合制作了一张《北京露营地图》,非常精美,标注了北京周边 109 个露营地点,可收藏。点击图片可放大,再点击一下可以放到最大。