JBOPS icon indicating copy to clipboard operation
JBOPS copied to clipboard

Bad Request error Unsharing when "no shared libraries"

Open irodimus opened this issue 4 years ago • 7 comments

This issue kinda goes back to issue #163 where attempting to unshare libraries from a user that currently does not have any shared libraries checked gives this error using the remove_inactive_users.py script:

Traceback (most recent call last):
  File "remove_inactive_users.py", line 117, in <module>
    ACCOUNT.updateFriend(PLEX_USERS[UID], SERVER, SECTIONS, removeSections=True)
  File "/usr/local/lib/python3.7/site-packages/plexapi/myplex.py", line 283, in updateFriend
    response_servers = self.query(url, self._session.delete, json=params, headers=headers)
  File "/usr/local/lib/python3.7/site-packages/plexapi/myplex.py", line 176, in query
    raise BadRequest('(%s) %s %s; %s' % (response.status_code, codename, response.url, errtext))
plexapi.exceptions.BadRequest: (404) not_found https://plex.tv/api/servers/20253b4dc5cce18dc752eb4dfeebf9eb9eeea237/shared_servers; <!DOCTYPE html> <html> <head>   <title>The page you were looking for doesn't exist (404)</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', '/404?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 404 error...</h1>     <h2>That's "page not found" in human language.</h2>     <p>You may have mistyped the address or the page may have moved.<br/>   	  <a href="/">Let us take you to the main page</a> and we can start all over again, shall we?     </p>   </div> </div> </body> </html>

I'm wondering if this is more an issue with PlexAPI than the the script. Is there any way to check?

irodimus avatar Sep 28 '19 03:09 irodimus

@DirtyCajunRice If an user has already been unshared the script will continue to check the user's history until they've been inactive for so long that they'll be removed. So there is a gap where this issue will continue to present itself.

Maybe add a check before unsharing,

    elif TOTAL_SECONDS >= (UNSHARE_LIMIT * 86400):
        if DRY_RUN:
            print('{}, and would unshare libraries.'.format(OUTPUT))
        else:
            print('{}, and has reached their inactivity limit. Unsharing.'.format(OUTPUT))
            for server in ACCOUNT.user(PLEX_USERS[UID]).servers:
                if server.name == SERVER.friendlyname and server.sections():
                    ACCOUNT.updateFriend(PLEX_USERS[UID], SERVER, SECTIONS, removeSections=True)
                else:
                    print("User already unshared")

blacktwin avatar Sep 30 '19 17:09 blacktwin

@irodimus Can you make the edits above and confirm?

blacktwin avatar Oct 02 '19 17:10 blacktwin

Odd. I never got this notification. Ill get it.

dirtycajunrice avatar Oct 02 '19 17:10 dirtycajunrice

Anything else needed for this? @irodimus @DirtyCajunRice

blacktwin avatar Oct 23 '19 01:10 blacktwin

I had not seen an update for the fix that had been mentioned here, although the initial issue had been resolved.

irodimus avatar Oct 23 '19 01:10 irodimus

@irodimus @DirtyCajunRice can we work this out? either in this issue or the PR? Looking at the PR comments I'm trying to figure out the reproduction steps.

  1. User has no shares but still a user
  2. When script is ran (DRY) user is not mentioned
    • If not DRY script works as intended

Is that correct?

blacktwin avatar Feb 21 '20 15:02 blacktwin

I had a chance to look over this issue. The original bug appears to be resolved and the error no longer occurs. The only thing I did notice is that once the user's libraries were unshared, rerunning the script will not print out this line from the script:

                else:
                    print("{}, has already been unshared, but has not reached their shareless threshold."
                          "Skipping.".format(OUTPUT))

The users who had their libraries unshared don't have any output at all and are not mentioned even though they are still users on the server.

I ran the script as dry run and normally and it didn't appear to make a difference. The result was the same. I wasn't able to test if the user was eventually removed from the server once they reached the remove threshold. I will keep an eye out for that.

irodimus avatar Dec 10 '20 02:12 irodimus