Plex Unexpected error

I’m trying to add Plex Media Server inside HA.

Selected the option “Obtain a new token from plex.tv

After login to Plex, It goes back to HA with “Unexpected error”

Any idea why?

Try running the Plex integration in debug mode and try again. If it’s still not clear, please create a github issue on core.

How do I run it in debug mode?

Open the Plex panel from the Integrations page and select “Enable debug logging”.

ok… found this

any idea?

2024-04-08 18:14:25.337 WARNING (ImportExecutor_0) [py.warnings] /usr/local/lib/python3.12/site-packages/plexapi/base.py:174: SyntaxWarning: invalid escape sequence '\d'
  """ Load the specified key to find and build all items with the specified tag

2024-04-08 18:14:37.140 ERROR (MainThread) [homeassistant.components.plex] Unknown error connecting to Plex server: 'list' object has no attribute 'tag'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/plex/config_flow.py", line 197, in async_step_server_validate
    await self.hass.async_add_executor_job(plex_server.connect)
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/plex/server.py", line 214, in connect
    _connect_with_token()
  File "/usr/src/homeassistant/homeassistant/components/plex/server.py", line 146, in _connect_with_token
    x for x in self.account.resources() if "server" in x.provides
               ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/plexapi/myplex.py", line 296, in resources
    return [MyPlexResource(self, elem) for elem in data]
            ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/plexapi/base.py", line 70, in __init__
    self._loadData(data)
  File "/usr/local/lib/python3.12/site-packages/plexapi/myplex.py", line 1439, in _loadData
    self.connections = self.findItems(data, ResourceConnection, rtag='connections')
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/plexapi/base.py", line 342, in findItems
    items = MediaContainer[cls](self._server, data, initpath=initpath) if data.tag == 'MediaContainer' else []
                                                                          ^^^^^^^^
2024-04-08 18:20:12.478 ERROR (MainThread) [homeassistant.components.hassio] Failed to to call /addons/a0d7b954_plex/stats - Container addon_a0d7b954_plex is not running
2024-04-08 18:20:30.707 ERROR (MainThread) [homeassistant.components.plex] Unknown error connecting to Plex server: 'list' object has no attribute 'tag'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/plex/config_flow.py", line 197, in async_step_server_validate
    await self.hass.async_add_executor_job(plex_server.connect)
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/plex/server.py", line 214, in connect
    _connect_with_token()
  File "/usr/src/homeassistant/homeassistant/components/plex/server.py", line 146, in _connect_with_token
    x for x in self.account.resources() if "server" in x.provides
               ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/plexapi/myplex.py", line 296, in resources
    return [MyPlexResource(self, elem) for elem in data]
            ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/plexapi/base.py", line 70, in __init__
    self._loadData(data)
  File "/usr/local/lib/python3.12/site-packages/plexapi/myplex.py", line 1439, in _loadData
    self.connections = self.findItems(data, ResourceConnection, rtag='connections')
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/plexapi/base.py", line 342, in findItems
    items = MediaContainer[cls](self._server, data, initpath=initpath) if data.tag == 'MediaContainer' else []
                                                                          ^^^^^^^^
2024-04-08 20:49:26.108 ERROR (MainThread) [homeassistant.components.hassio] Failed to to call /addons/a0d7b954_plex/stats - Addon is not installed
2024-04-08 20:49:27.429 ERROR (MainThread) [homeassistant.components.hassio] Failed to to call /addons/a0d7b954_plex/stats - Addon is not installed
2024-04-08 20:49:30.575 ERROR (MainThread) [homeassistant.components.hassio] Failed to to call /addons/a0d7b954_plex/uninstall - Addon is not installed
2024-04-08 20:52:31.153 ERROR (MainThread) [homeassistant.components.plex] Unknown error connecting to Plex server: 'list' object has no attribute 'tag'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/plex/config_flow.py", line 197, in async_step_server_validate
    await self.hass.async_add_executor_job(plex_server.connect)
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/plex/server.py", line 214, in connect
    _connect_with_token()
  File "/usr/src/homeassistant/homeassistant/components/plex/server.py", line 146, in _connect_with_token
    x for x in self.account.resources() if "server" in x.provides
               ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/plexapi/myplex.py", line 296, in resources
    return [MyPlexResource(self, elem) for elem in data]
            ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/plexapi/base.py", line 70, in __init__
    self._loadData(data)
  File "/usr/local/lib/python3.12/site-packages/plexapi/myplex.py", line 1439, in _loadData
    self.connections = self.findItems(data, ResourceConnection, rtag='connections')
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/plexapi/base.py", line 342, in findItems
    items = MediaContainer[cls](self._server, data, initpath=initpath) if data.tag == 'MediaContainer' else []
                                                                          ^^^^^^^^
AttributeError: 'list' object has no attribute 'tag'

I’d guess the response to this payload is missing info needed to connect to your server:

$ curl -H 'X-Plex-Token: <YOUR_TOKEN_HERE>' -H 'X-Plex-Client-Identifier: <YOUR_CLIENT_ID_HERE>' 'https://plex.tv/api/v2/resources?includeHttps=1&includeRelay=1'

Be careful not to post your token or personal info from the response.

You can steal a token from a Plex Web session by hitting “…” on any media, selecting “Get Info”, and then “View XML”. The token will be in the URL. The client ID can be any string, I believe.

You also have errors about the Plex addon not running. Could this be as simple as your Plex server being down?

I didn’t post a token above… right?

My Plex Server is running on different server, is not on the same box as HA.

No, but you can get a token and make that curl call to get more info.

Did you ever figure this out? Same thing happening to me.

I believe this is a library issue. Will be bumping it with a fix soon.

I hope Bump plexapi to 4.15.12 by jjlawren · Pull Request #115872 · home-assistant/core · GitHub will resolve this.

is fixed now :slight_smile:

Thank you