Skip to content
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

Cannot control client : 406 error #244

Closed
niko34 opened this issue Jan 3, 2018 · 22 comments
Closed

Cannot control client : 406 error #244

niko34 opened this issue Jan 3, 2018 · 22 comments
Assignees
Labels

Comments

@niko34
Copy link

niko34 commented Jan 3, 2018

Hi,

i try to control a plex client (PMP on a RPI) using python-plexapi.

I get a token after using plex-listtokens.py. The tool list many object : Ressources, Devices and one client (my PMP RPI). My Plex Media Server (Ressource) has the same token than my Plex Media Player (Client).

I made a small python script, where the baseurl is the url of my plex server.
When i print the clients list, i can see my client with the title "PlexMediaPlayer".
As a result of this script, i always get a 406 error code, with this trace :

PlexMediaPlayer
Traceback (most recent call last):
  File "./test.py", line 16, in <module>
    client.goToHome()
  File "/usr/local/lib/python2.7/dist-packages/plexapi/client.py", line 216, in goToHome
    self.sendCommand('navigation/home')
  File "/usr/local/lib/python2.7/dist-packages/plexapi/client.py", line 192, in sendCommand
    return self.query(key, headers=headers)
  File "/usr/local/lib/python2.7/dist-packages/plexapi/client.py", line 164, in query
    raise BadRequest('(%s) %s; %s %s' % (response.status_code, codename, response.url, errtext))
plexapi.exceptions.BadRequest: (406) not_acceptable; http://10.0.1.35:32433/player/navigation/home?commandID=1&X-Plex-Token=[MY TOKEN]

Is there any step i did forget to control my client ?
(i can navigate into my library thru the PlexServer object, list all my movies...)

#!/usr/bin/env python3

from plexapi.server import PlexServer

baseurl = 'http://10.0.1.41:32400'
token = '[MY TOKEN]'
plex = PlexServer(baseurl, token)

for client in plex.clients():
    print(client.title)

client = plex.client("PlexMediaPlayer")

client.connect()

client.goToHome()
@Hellowlol
Copy link
Collaborator

Hellowlol commented Jan 3, 2018

What happens if you pass the url in your browser, are there any error message from pmp?

@niko34
Copy link
Author

niko34 commented Jan 3, 2018

I only get a generic message in chrome : "Failed to load resource: the server responded with a status of 406 (Not Acceptable)".

@Hellowlol
Copy link
Collaborator

Thanks, ill check.

@pkkid
Copy link
Owner

pkkid commented Jan 3, 2018

The /navigation commands are hit more miss on many of the clients. I imagine even more so since the clients have been getting so many updates from the Plex team. You might want to try playing a media item directly to see if you get the same error.

@pkkid
Copy link
Owner

pkkid commented Jan 3, 2018

@Hellowlol Would it make sense for us to also log the response body when we a bad request (400 level)? As you mentioned that's often where the useful error messages are sitting.

@pkkid
Copy link
Owner

pkkid commented Jan 5, 2018

FWIW 406 = Not Acceptable

@Hellowlol
Copy link
Collaborator

Yes. I think so.

@ryanm101
Copy link
Collaborator

One of our users has reported the same issue. You might want to check out our ticket incase it provides any more detail

@Hellowlol
Copy link
Collaborator

I know notice that I posted in the home assistant issue. Anyway pmp seems to require a timeline call every 90 sec or it throws a 406 on the command.

You can fix this by using client.timeline()

@ryanm101
Copy link
Collaborator

Just to answer your semi-rhetorical question in the HomeAssistant I would think it best handled in the at the API level if it can be done async. If not and it's going to block then it should be handled by the implementor.

@Hellowlol
Copy link
Collaborator

Nothing about this api is asynchronous. Anyway I think we should handle this this is the client class.

@Hellowlol
Copy link
Collaborator

If anybody want to send a pr please do if not I’ll fix this after I’m done with bw_plex

@doodah33
Copy link

Any ETA on a fix for this? Thanks!

@pkkid pkkid added the bug label Jun 23, 2018
@Hellowlol
Copy link
Collaborator

Hellowlol commented Sep 3, 2018

@doodah33 Today :) hopefully ;)

@Hellowlol Hellowlol self-assigned this Sep 3, 2018
@realfire23
Copy link

any news out there ? iam getting the same error.

Also Iam unable to cast videos.

Problem appears when trying to cast on windows plex media player (which is indeed crucial for me,
because of the orientation of screen.

@Hellowlol
Copy link
Collaborator

I have tried to add a fix in https://github.com/pkkid/python-plexapi/tree/pmp_406 Can anybody test and confirm?

@beville
Copy link

beville commented Nov 17, 2018

I just gave it go by copying client.py into my Home Assistant deps. The 406 error is gone, and I'm able to control the Plex Media Player on RPi.

Nice work!

@Hellowlol
Copy link
Collaborator

@beville you mind trying different actions like pause, stop, play, vol up down etc?

@beville
Copy link

beville commented Nov 17, 2018

Yes, I tested play, pause, stop, volume up and down via the HA control, and all worked.

In addition, I used the test script from above at #244 (comment), and the goToHome function seemed to work.

Since this problem seems to affect PMP regardless of platform, you should be able to easily verify yourself against any desktop version of PMP. I just started a Linux version of PMP (https://knapsu.eu/plex/), and was able to pause/play with a script using your fixed version of client.py.

@Hellowlol
Copy link
Collaborator

Thanks for confirming. I’ll see if I can get this merged later.

@Hellowlol
Copy link
Collaborator

Closing this as the pr is merged in master.

@jjlawren
Copy link
Collaborator

While researching some details around timeline() I figured I'd test if this workaround is still necessary. Unfortunately I can still reproduce the problem in the latest version (v2.58.0) which was released in May 2020. Too bad.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants