ParseError: not well-formed (invalid token) using cElementTree

前端 未结 13 1112
日久生厌
日久生厌 2020-12-16 11:10

I receive xml strings from an external source that can contains unsanitized user contributed content.

The following xml string gave a ParseError in cElementTre

13条回答
  •  余生分开走
    2020-12-16 11:30

    The only thing that worked for me is I had to add mode and encoding while opening the file like below:

    with open(filenames[0], mode='r',encoding='utf-8') as f:
         readFile()
    

    Otherwise it was failing every time with invalid token error if I simply do this:

     f = open(filenames[0], 'r')
     readFile()
    

提交回复
热议问题