8000 Catch additional exception for Plex account login failures by jjlawren · Pull Request #37143 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Catch additional exception for Plex account login failures 8000 #37143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 26, 2020

Conversation

jjlawren
Copy link
Contributor

Proposed change

The fix for handling unauthenticated Plex servers in #37096 was incomplete as the Plex endpoints sometimes return unexpected HTTP error codes. This PR catches a 'fallback' exception for those instances.

Example traceback:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 220, in async_setup
    hass, self
  File "/usr/src/homeassistant/homeassistant/components/plex/__init__.py", line 170, in async_setup_entry
    plex_account = await hass.async_add_executor_job(get_plex_account, plex_server)
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/plex/__init__.py", line 166, in get_plex_account
    return plex_server.account
  File "/usr/src/homeassistant/homeassistant/components/plex/server.py", line 100, in account
    self._plex_account = plexapi.myplex.MyPlexAccount(token=self._token)
  File "/usr/local/lib/python3.7/site-packages/plexapi/myplex.py", line 94, in __init__
    data, initpath = self._signin(username, password, timeout)
  File "/usr/local/lib/python3.7/site-packages/plexapi/myplex.py", line 99, in _signin
    return self.query(self.key), self.key
  File "/usr/local/lib/python3.7/site-packages/plexapi/myplex.py", line 195, in query
    raise BadRequest(message)
plexapi.exceptions.BadRequest: (422) unprocessable_entity; https://plex.tv/users/account <?xml version="1.0" encoding="UTF-8"?> <errors>   <error>Invalid token</error> </errors>

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

Copy link
Member
@balloob balloob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Does this need to go into 112?

@balloob balloob merged commit fe5bf96 into home-assistant:dev Jun 26, 2020
@@ -98,7 +98,7 @@ def account(self):
if not self._plex_account and self._use_plex_tv:
try:
self._plex_account = plexapi.myplex.MyPlexAccount(token=self._token)
except Unauthorized:
except (BadRequest, Unauthorized):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bad Request is HTTP status code 400, your initial post showed a 422. Does this work ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jjlawren jjlawren added this to the 0.112.0 milestone Jun 26, 2020
@jjlawren jjlawren deleted the fix_plex_account_exception branch June 26, 2020 18:26
hahn-th pushed a commit to hahn-th/core that referenced this pull request May 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0