JBOPS
JBOPS copied to clipboard
Bad Request error Unsharing when "no shared libraries"
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?
@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")
@irodimus Can you make the edits above and confirm?
Odd. I never got this notification. Ill get it.
Anything else needed for this? @irodimus @DirtyCajunRice
I had not seen an update for the fix that had been mentioned here, although the initial issue had been resolved.
@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.
- User has no shares but still a user
- When script is ran (DRY) user is not mentioned
- If not DRY script works as intended
Is that correct?
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.