Skip to content

Error "not well-formed (invalid token)" when getting watchlist due to "end of transmission" character in movie review  #1450

@austin-agronick

Description

@austin-agronick

Describe the Bug

I am getting this error after adding 'How to Rob a Bank' to my plex watchlist. After debugging I confirmed that it was this part of the xml that was causing the error:

<Review image="rottentomatoes://image.review.fresh"
                link="https://www.commonsensemedia.org/movie-reviews/how-to-rob-a-bank"
                source="Common Sense Media" tag="Barbara Shulgasser"
                text="How to Rob a Bank is a straightforward, workmanlike documentary that effectively tells the story of man who lived in a large treehouse, cooked meth in his own lab, then switched careers for bank robbing\x04."/>

Specifically the \x04 character causes

         │ /home/austin/.asdf/installs/python/3.11.2/lib/python3.11/xml/etree/ElementTree.py:1338 in XML                                                                                                                                                                                                               │
         │                                                                                                                                                                                                                                                                                                             │
         │   1335 │   """                                                                                                                                                                                                                                                                                              │
         │   1336 │   if not parser:                                                                                                                                                                                                                                                                                   │
         │   1337 │   │   parser = XMLParser(target=TreeBuilder())                                                                                                                                                                                                                                                     │
         │ ❱ 1338 │   parser.feed(text)                                                                                                                                                                                                                                                                                │
         │   1339 │   return parser.close() 

to fail with ParseError: not well-formed (invalid token): line 1, column 20416.

If I set a breakpoint at parser.feed(text) and try to execute parser.feed(text) it will show this error. However if I run parser.feed(text.replace(b'\x04', b'')) it does not error.

Some input validation or filtering may be needed to resolve this as the error seems to come directly from the reviewer's site. The issue probably needs to be resolved in myplex.query when passing data to ElementTree.fromstring(data) if data.strip() else None

Code Snippets

self.plex.watchlist()

Expected Behavior

No response

Additional Context

No response

Operating System and Version

Kubuntu 24.04

Plex Media Server Version

Unknown

Python Version

3.11.2

PlexAPI Version

4.15.15

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions