RemiRigal/Plex-Auto-Languages

[ERROR] Unable to process playing

BEisem opened this issue · 12 comments

Lately I've been seeing a lot of errors in the logs that look like this:

2022-06-13 18:15:00,278 [ERROR] Unable to process playing
Traceback (most recent call last):
  File "/app/plex_auto_languages/plex_alert_handler.py", line 43, in __call__
    alert.process(self._plex)
  File "/app/plex_auto_languages/alerts/playing.py", line 45, in process
    user_plex = plex.get_plex_instance_of_user(user_id)
  File "/app/plex_auto_languages/plex_server.py", line 168, in get_plex_instance_of_user
    matching_users = [u for u in self.get_instance_users() if str(u.id) == str(user_id)]
  File "/app/plex_auto_languages/plex_server.py", line 155, in get_instance_users
    for user in self._plex.myPlexAccount().users():
  File "/usr/local/lib/python3.8/site-packages/plexapi/myplex.py", line 505, in users
    elem = self.query(MyPlexUser.key)
  File "/usr/local/lib/python3.8/site-packages/plexapi/myplex.py", line 183, in query
    raise BadRequest(message)
plexapi.exceptions.BadRequest: (502) bad_gateway; https://plex.tv/api/users/ <!DOCTYPE html> <html> <head>   <title>We're sorry, but something went wrong (500)</title> <link href="/assets/errors.css" media="screen" rel="stylesheet" type="text/css" />   <script type="text/javascript">     var _gaq = _gaq || [];     _gaq.push(['_setAccount', 'UA-6111912-23']);     _gaq.push(['_setDomainName', 'plex.tv']);     _gaq.push(['_trackPageview', '/500?url=' + window.location.pathname]);     (function() {       var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;       ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';       var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);     })();   </script> </head>  <body>   <div class="block">     <div class="dialog">            <h1>Oops; a 500 error...</h1>       <h2>That's "Internal Server Error" in geeky language.</h2>       <p>We've been notified about this issue and will take a look at it shortly.<br/>          <a href="/">Let us take you to the main page</a> and we can start all over again, shall we?       </p>       <p>You can always visit <a href="https://status.plex.tv/">status.plex.tv</a> for current information. Thank you for your patience.</p>     </div>   </div> </body> </html> 

Please let me know any other info you might need.

Also seeing "Unable to process status"

2022-06-14 20:43:55,453 [ERROR] Unable to process status
Traceback (most recent call last):
  File "/app/plex_auto_languages/plex_alert_handler.py", line 43, in __call__
    alert.process(self._plex)
  File "/app/plex_auto_languages/alerts/status.py", line 44, in process
    plex.process_new_or_updated_episode(item.key, EventType.NEW_EPISODE, True)
  File "/app/plex_auto_languages/plex_server.py", line 201, in process_new_or_updated_episode
    user_plex = self.get_plex_instance_of_user(user_id)
  File "/app/plex_auto_languages/plex_server.py", line 168, in get_plex_instance_of_user
    matching_users = [u for u in self.get_instance_users() if str(u.id) == str(user_id)]
  File "/app/plex_auto_languages/plex_server.py", line 155, in get_instance_users
    for user in self._plex.myPlexAccount().users():
  File "/usr/local/lib/python3.8/site-packages/plexapi/myplex.py", line 505, in users
    elem = self.query(MyPlexUser.key)
  File "/usr/local/lib/python3.8/site-packages/plexapi/myplex.py", line 183, in query
    raise BadRequest(message)
plexapi.exceptions.BadRequest: (502) bad_gateway; https://plex.tv/api/users/ <!DOCTYPE html> <html> <head>   <title>We're sorry, but something went wrong (500)</title> <link href="/assets/errors.css" media="screen" rel="stylesheet" type="text/css" />   <script type="text/javascript">     var _gaq = _gaq || [];     _gaq.push(['_setAccount', 'UA-6111912-23']);     _gaq.push(['_setDomainName', 'plex.tv']);     _gaq.push(['_trackPageview', '/500?url=' + window.location.pathname]);     (function() {       var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;       ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';       var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);     })();   </script> </head>  <body>   <div class="block">     <div class="dialog">            <h1>Oops; a 500 error...</h1>       <h2>That's "Internal Server Error" in geeky language.</h2>       <p>We've been notified about this issue and will take a look at it shortly.<br/>          <a href="/">Let us take you to the main page</a> and we can start all over again, shall we?       </p>       <p>You can always visit <a href="https://status.plex.tv/">status.plex.tv</a> for current information. Thank you for your patience.</p>     </div>   </div> </body> </html> 

This has begun happening more and more, practically making the script useless. I've even tried deleting the cache file so it will rebuild from scratch. Any ideas or suggestions?

In both cases this seems to point to an internal server error on Plex side, i.e. the plex.tv server is not reachable or is having issues. What can be done in PlexAutoLanguages is to improve the way these errors are logged but I can't do anything about the availability of Plex own servers...

@BEisem are you still experiencing this issue ?

I do experience it occasionally. It's hit or miss, happens sometimes but I don't really know when or how it triggers.

But I understand it is not an issue with pal, but a Plex problem.

Just out of curiosity, the Plex URL I have set up in the config file is a local url (i.e. http://127.0.0.1:34000). Why would it be trying to go through the plex.tv url instead of accessing it locally?

(I'm still getting this regularly, btw)

Just out of curiosity, the Plex URL I have set up in the config file is a local url (i.e. http://127.0.0.1:34000). Why would it be trying to go through the plex.tv url instead of accessing it locally?

The authentication is always handled by their own servers and is required to be able to access your own instance. All the clients that you use require an internet access even when you are on the same network as your own server.

In the case of PAL, your users are also retrieved from your Plex account, which requires calls to plex.tv. The traceback you provided in this issue clearly states that the issue happens during the call to self._plex.myPlexAccount().users() which retrieves the users of your account. I'm working on caching this information so that PAL can fallback to the cache if the request is not successful, it's a reasonable compromise IMO.

I think a cache of the users is a great idea. Perhaps rather than using it as a fallback, you can access the cache first, and if the user is not found in the cache, then you can call the Plex api. Just a thought, since users will not change very often.

The issue with using the cache first is that for new/updated episodes you want to change the tracks for all your users, so you will not be able to know if you are missing one or more users.

I've implemented and merged (#52) what I think is a good compromise. The cache is always used first but is invalidated every 12 hours. If the refresh goes wrong (the BadRequest you have for example), the previously invalidated cache is used anyway.

@RemiRigal I began seeing the following with the most recent update -

2022-09-09 10:47:21,358 [ERROR] Unable to process playing Traceback (most recent call last): File "/app/plex_auto_languages/plex_alert_handler.py", line 61, in _process_alerts alert.process(self._plex) File "/app/plex_auto_languages/alerts/playing.py", line 79, in process plex.change_tracks(username, item, EventType.PLAY_OR_ACTIVITY) File "/app/plex_auto_languages/plex_server.py", line 250, in change_tracks track_changes.compute(episodes) File "/app/plex_auto_languages/track_changes.py", line 91, in compute self._update_description(episodes) File "/app/plex_auto_languages/track_changes.py", line 121, in _update_description min_episode_number = min([e.episodeNumber for e in episodes if e.seasonNumber == min_season_number]) TypeError: '<' not supported between instances of 'int' and 'NoneType'

plex version 1.27.2.5929

@RemiRigal I began seeing the following with the most recent update -

2022-09-09 10:47:21,358 [ERROR] Unable to process playing Traceback (most recent call last): File "/app/plex_auto_languages/plex_alert_handler.py", line 61, in _process_alerts alert.process(self._plex) File "/app/plex_auto_languages/alerts/playing.py", line 79, in process plex.change_tracks(username, item, EventType.PLAY_OR_ACTIVITY) File "/app/plex_auto_languages/plex_server.py", line 250, in change_tracks track_changes.compute(episodes) File "/app/plex_auto_languages/track_changes.py", line 91, in compute self._update_description(episodes) File "/app/plex_auto_languages/track_changes.py", line 121, in _update_description min_episode_number = min([e.episodeNumber for e in episodes if e.seasonNumber == min_season_number]) TypeError: '<' not supported between instances of 'int' and 'NoneType'

plex version 1.27.2.5929

Same here. I got the answer from Copilot.

This error is occurring because the program is trying to find the minimum episode number, but it encounters a None value. The None type cannot be compared with integers. Specifically, this error occurs in the plex_auto_languages/track_changes.py file on line 121 when executing the line of code min_episode_number = min([e.episodeNumber for e in episodes if e.seasonNumber == min_season_number]).

This suggests that the episodeNumber attribute of an element in the episodes list might be None. You may need to check the contents of this list to ensure that all episodes have a valid episodeNumber. If an episode does not have a number, you will need to decide how to handle this, such as skipping the episode or assigning it a default number.

0

My issue is that there's an episode in the show named by date instead of having an episode number, which causes an error. I think this is a bug that needs fixing. Items without an episode number should also be synchronized and set accordingly.