Python python parsing xml file error Xml.parsers.expat.ExpatError:unknown encoding resolution __python
Source: Internet
Author: User
Python parsing xml file error: Xml.parsers.expat.ExpatError:unknown encoding:line 1, column 30
This is due to coding problems.
Reason Description:
The LANG=ZH_CN of the shell environment. UTF-8
Executes a program that generates an XML file that sets the encoding of the XML file to GB2312 in the program, such as "<?xml version=" 1.0 "encoding=" GB2312 "?>".
Then, using Xml.etree.ElementTree to parse the XML file, an error occurred: "Xml.parsers.expat.ExpatError:unknown encoding:line 1, column 30."
In fact, because of Lang's role, the program generates XML file encoding is UTF-8, not GB2312, so parsing error occurred.
(Viewing the text file encoding can be performed under VIM: Set fileencoding to view.) )
Solution:
Converts an XML file encoding to GB2312, such as using the Iconv command,
Or
Modify the encoding of the XML file to UTF-8, such as: "<?xml version=" 1.0 "encoding=" UTF-8 "?>"
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.