我有这样XML解析问题编码错误
<?xml version="1.0" encoding="UTF-8"?>
<tw>
<tweet>
<yazi>atılacak tweet 1</yazi>
<resim>resim.png</resim>
</tweet>
<tweet>
<yazi>atılacak tweet 2</yazi>
<resim>yok</resim>
</tweet>
</tw>
一个XML文件,我想用
import xml.etree.ElementTree as ett
e = ett.parse("tweet.xml").getroot()
读它,但我得到这个错误,
xml.etree.ElementTree.ParseError: encoding specified in XML declaration is incorrect: line 1, column 31
为什么?我如何解决这个问题,我搜索了很多,XML文件看起来不错。我不明白为什么我不能读取文件。
无法复制。我复制粘贴到一个文件并运行此代码没有问题。 – idjaw
@idjaw嗯,我得到这个错误,我在Windows上工作 – GLHF
我无法复制你的错误。我将你粘贴的XML文件复制到一个文件中。我复制了该代码并运行它,它对我来说工作正常。我无法重现您的错误。 – idjaw