Python handling of XML encountered special symbolic parsing errors

Source: Internet
Author: User

global:[2017-06-05 10:27:48.662313] [DEBUG] output fmsg_content <msg fromusername= "li2571" Encryptusername= "V1_d[email  protected]stranger "Fromnickname="??? ? ?? ?????? E?? "content=" I Am "fullpy="????????????? "shortpy="????????????? "imagestatus=" 3 "scene=" 3 "country=" CN "province=" Hubei "city=" Jingzhou "sign=" 〢 rubidium wrap love, please love deeply. ,. |‖|‖▍. * "percard=" 1 "sex=" 2 "alias=" LiLizouli713 "weibo=" "Weibonickname=" "albumflag=" 0 "albumstyle=" 0 "albumbgimgid=" " Snsflag= "Snsbgimgid=" http://szmmsns.qpic.cn/mmsns/ aicqlel8roa2ojpnj8q8gf1ibvndx1x5hd23xde644eap8x0e5qtm69hgq5e6goquakiaku39cate8/0 "Snsbgobjectid=" 12548372440867024976 "mhash=" 3247e9c6ea7921d63e672c5ede4e206e "mfullhash=" 3247e9c6ea7921d63e672c5ede4e206e " Bigheadimgurl= "http://wx.qlogo.cn/mmhead/ver_1/ Kjw4hogeyiblpboxt4mudtuv9bhrnxat0c4dw7jvquy3tia8yf8ibbbgf7wrv9vaafdfclne8gybjllsvatrrknrp2zjjlxtp9vgkedcgciab44 /0 "smallheadimgurl=" http://wx.qlogo.cn/mmhead/ver_1/ Kjw4hogeyiblpboxt4mudtuv9bhrnxat0c4dw7jvquy3tia8yf8ibbbgf7wrv9vaafdfclne8gybjllsvatrRknrp2zjjlxtp9vgkedcgciab44/96 "ticket=" V2_8655444fac8ef7e3a277aeee973c6038a[email protected]stranger " Opcode= "2" googlecontact= "" qrticket= "" Chatroomusername= "" Sourceusername= "" Sourcenickname= "" ><brandlist count= "0" ver= "652744432" ></brandlist></msg>
global:[2017-06-05 10:27:48.662493] [DEBUG] Shuchuadezhi.     、. # this is fmsg_content[300:305]
global:[2017-06-05 10:27:48.662711] [ERROR] process_wechat_msg not well-formed (invalid tokens): Line 1, column 301

Import Xml.etree.cElementTree as ET

Xml_tree = et.fromstring (fmsg_content)

Run an error

global:[2017-06-05 10:27:48.662711] [ERROR] process_wechat_msg not well-formed (invalid tokens): Line 1, column 301

Output log

FMSG_CONTENT[300:305] got a special symbol. 、.

Try it first:

# parser = ET. Xmlparser (encoding= ' utf-8 ')

# Xml_tree = et.fromstring (fmsg_content, Parser=parser)

Get

Error in '/usr/bin/python3 ': double free or corruption (!prev): 0x00000000012ae500 * * *

Tai Hang.

Eventually

Fmsg_content=re.sub (U "[\x00-\x08\x0b-\x0c\x0e-\x1f]+", U "", fmsg_content)

Xml_tree = et.fromstring (fmsg_content)

Replacing illegal characters will not be an error.

Python handling of XML encountered special symbolic parsing errors

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.