home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
74.07k stars 31.09k forks source link

Plex Media Player BadRequest 406 error #13300

Closed beville closed 5 years ago

beville commented 6 years ago

Home Assistant release (hass --version): 0.65.5 Python release (python3 --version): Python 3.6.4 Component/platform: media_player/plex Description of problem: I have a Raspberry Pi with the embedded PlexMediaPlayer distro (official). In the HA home screen, the player card shows up, and accurately reflects the current state and media. However when I try to control the playback (pause/play/skip/stop) it doesn't work. If I look at the logs after I try, I see:

Error executing service <ServiceCall media_player.media_play_pause: entity_id=['media_player.plexmediaplayer_2']>
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/core.py", line 1006, in _event_to_service_call
    await service_handler.func(service_call)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/media_player/__init__.py", line 402, in async_service_handler
    yield from getattr(player, method['method'])(**params)
  File "/usr/local/Cellar/python/3.6.4_4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/futures.py", line 327, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/local/Cellar/python/3.6.4_4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/tasks.py", line 250, in _wakeup
    future.result()
  File "/usr/local/Cellar/python/3.6.4_4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/futures.py", line 243, in result
    raise self._exception
  File "/usr/local/Cellar/python/3.6.4_4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/media_player/plex.py", line 691, in media_play
    self.device.play(self._active_media_plexapi_type)
  File "/Users/tony/.homeassistant/deps/lib/python/site-packages/plexapi/client.py", line 304, in play
    self.sendCommand('playback/play', type=mtype)
  File "/Users/tony/.homeassistant/deps/lib/python/site-packages/plexapi/client.py", line 194, in sendCommand
    return self.query(key, headers=headers)
  File "/Users/tony/.homeassistant/deps/lib/python/site-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://192.168.3.16:32433/player/playback/play?commandID=1&type=video&X-Plex-Token=xxxxxxxxxxxxxxxxxxxxxx 

As a control, I am able to use HA to control my iPad when it has the Plex app running.

ryanm101 commented 6 years ago

Have you tried plex on any other devices such as chrome / andriod? If so does it work for them?

also how up to date is that media player distro?

beville commented 6 years ago

Yes. I just tested again with Plex iPad client, Plex Android client on my phone, and the web client (running in Chrome). With all three I was able to control (play/pause/stop/skip) the client from the HA card.

(There does seem to be a different error show up in the logs when controlling the Android client. I can paste in the full stack trace into another issue, if you like. Here's just the end:

  File "/Users/tony/.homeassistant/deps/lib/python/site-packages/plexapi/client.py", line 166, in query
    return ElementTree.fromstring(data) if data.strip() else None
  File "/usr/local/Cellar/python/3.6.4_4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/xml/etree/ElementTree.py", line 1314, in XML
    parser.feed(text)
  File "<string>", line None
xml.etree.ElementTree.ParseError: syntax error: line 1, column 0

Despite this, the controlling the Android client still works)

In addition, I just downloaded and ran Plex Media Player for Windows v2.6.0.803 on my laptop. I get the same error as I do when trying to control PMP on my Pi, so this should be easy to recreate if you don't have the embedded version. It seems that the new PMP maybe isn't taking commands the way the older clients are.

ryanm101 commented 6 years ago

I've a couple of pis laying about.. Windows being broken is good to know. Won't be able to do anything till next weekend to to work

ryanm101 commented 6 years ago

This might be an upstream issue: https://github.com/pkkid/python-plexapi/issues/244#issuecomment-355006430

Hellowlol commented 6 years ago

Pmp just seems to be more sensitive then over clients about timeline calls. It seems to make a 406 error if its more then 90 sec since a client.timeline() call.

Dunno if we should just check for this using a internal counter and just handle this just for pmp or if we should require the the user to handle it. This that i used to test it.

import logging
import time
logging.basicConfig(level=logging.DEBUG)

#logging.getLogger("urllib3").setLevel(logging.WARNING)
#logging.getLogger("requests").setLevel(logging.WARNING)
from plexapi.server import PlexServer

url = 'http://10.0.0.22:32400'
token = ''
s = PlexServer(url, token)

c = s.clients()[0]

m = s.search('12 year a slave')[0]

#print(c.product)

c.playMedia(m)
#c.timeline()
time.sleep(91)

c.timeline()
#c.pause()
c.seekTo(600*1000)
balloobbot commented 6 years ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.

Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment :+1:

ryanm101 commented 6 years ago

.

doodah33 commented 6 years ago

Issue appears unresolved. HA version 0.71.0

Traceback (most recent call last):                                                                                                                             
  File "/usr/src/app/homeassistant/core.py", line 1007, in _event_to_service_call                                                                              
    await service_handler.func(service_call)                                                                                                                   
  File "/usr/src/app/homeassistant/components/media_player/__init__.py", line 415, in async_service_handler                                                    
    await getattr(player, method['method'])(**params)                                                                                                          
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run                                                                                
    result = self.fn(*self.args, **self.kwargs)                                                                                                                
  File "/config/custom_components/media_player/plex.py", line 721, in media_play                                                                               
    self.device.play(self._active_media_plexapi_type)                                                                                                          
  File "/usr/local/lib/python3.6/site-packages/plexapi/client.py", line 307, in play                                                                           
    self.sendCommand('playback/play', type=mtype)                                                                                                              
  File "/usr/local/lib/python3.6/site-packages/plexapi/client.py", line 195, in sendCommand                                                                    
    return self.query(key, headers=headers)                                                                                                                    
  File "/usr/local/lib/python3.6/site-packages/plexapi/client.py", line 165, in query                                                                          
    raise BadRequest('(%s) %s; %s %s' % (response.status_code, codename, response.url, errtext))                                                               
plexapi.exceptions.BadRequest: (406) not_acceptable; http://192.168.1.2:32433/player/playback/play?commandID=1&type=video
balloobbot commented 6 years ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.

Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment :+1:

beville commented 6 years ago

Just tested, and this is still broken as of 0.81.1

Hertizch commented 5 years ago

Still issue on version 0.84.1

Hellowlol commented 5 years ago

Ill see if i cant push a new version off plexapi to pypi. The 406 error for pmp should be fixed

balloobbot commented 5 years ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.

Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment :+1:

thrust15 commented 5 years ago

I'm experiencing this issue from 0.91.0. I didn't have this before.

rdehuyss commented 5 years ago

I have the following in my logs:

2019-07-04 17:50:45 INFO (MainThread) [homeassistant.helpers.script] Script ring_on_sonos: Executing step Pause media
2019-07-04 17:50:45 WARNING (MainThread) [homeassistant.helpers.service] Not passing an entity ID to a service to target all entities is deprecated. Update your call to media_player.media_pause to be instead: entity_id: all
2019-07-04 17:50:45 WARNING (SyncWorker_12) [pychromecast.controllers] PAUSE command requested but no session is active.
2019-07-04 17:50:45 ERROR (MainThread) [homeassistant.core] Error executing service <ServiceCall script.ring_on_sonos (c:4e10a77b1b69490fb7fd34bd2403e0fb)>
Traceback (most recent call last):
  File "/usr/src/app/homeassistant/core.py", line 1150, in _safe_execute
    await self._execute_service(handler, service_call)
  File "/usr/src/app/homeassistant/core.py", line 1163, in _execute_service
    await handler.func(service_call)
  File "/usr/src/app/homeassistant/components/script/__init__.py", line 114, in service_handler
    context=service.context)
  File "/usr/src/app/homeassistant/components/script/__init__.py", line 172, in async_turn_on
    kwargs.get(ATTR_VARIABLES), context)
  File "/usr/src/app/homeassistant/helpers/script.py", line 131, in async_run
    await self._handle_action(action, variables, context)
  File "/usr/src/app/homeassistant/helpers/script.py", line 210, in _handle_action
    action, variables, context)
  File "/usr/src/app/homeassistant/helpers/script.py", line 299, in _async_call_service
    context=context
  File "/usr/src/app/homeassistant/helpers/service.py", line 89, in async_call_from_config
    domain, service_name, service_data, blocking=blocking, context=context)
  File "/usr/src/app/homeassistant/core.py", line 1141, in async_call
    self._execute_service(handler, service_call))
  File "/usr/src/app/homeassistant/core.py", line 1163, in _execute_service
    await handler.func(service_call)
  File "/usr/src/app/homeassistant/helpers/entity_component.py", line 194, in handle_service
    required_features
  File "/usr/src/app/homeassistant/helpers/service.py", line 316, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/app/homeassistant/helpers/service.py", line 337, in _handle_service_platform_call
    await getattr(entity, func)(**data)
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/app/homeassistant/components/plex/media_player.py", line 762, in media_pause
    self.device.pause(self._active_media_plexapi_type)
  File "/usr/local/lib/python3.7/site-packages/plexapi/client.py", line 299, in pause
    self.sendCommand('playback/pause', type=mtype)
  File "/usr/local/lib/python3.7/site-packages/plexapi/client.py", line 195, in sendCommand
    return self.query(key, headers=headers)
  File "/usr/local/lib/python3.7/site-packages/plexapi/client.py", line 167, in query
    return ElementTree.fromstring(data) if data.strip() else None
  File "/usr/local/lib/python3.7/xml/etree/ElementTree.py", line 1315, in XML
    parser.feed(text)
  File "<string>", line None
xml.etree.ElementTree.ParseError: syntax error: line 1, column 0
ianhyzy commented 5 years ago

I'm also seeing this, here's my logs:

plexapi.exceptions.BadRequest: (406) not_acceptable; http://192.168.1.222:32433/player/playback/pause?commandID=1&type=music 
2019-07-06 23:58:27 WARNING (SyncWorker_6) [plexapi] BadRequest (406) not_acceptable http://192.168.1.222:32433/player/playback/pause?commandID=1&type=music; 
2019-07-06 23:58:27 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection.139995045765248] (406) not_acceptable; http://192.168.1.222:32433/player/playback/pause?commandID=1&type=music 
Traceback (most recent call last):
  File "/usr/src/app/homeassistant/components/websocket_api/commands.py", line 121, in handle_call_service
    connection.context(msg))
  File "/usr/src/app/homeassistant/core.py", line 1150, in async_call
    self._execute_service(handler, service_call))
  File "/usr/src/app/homeassistant/core.py", line 1172, in _execute_service
    await handler.func(service_call)
  File "/usr/src/app/homeassistant/helpers/entity_component.py", line 194, in handle_service
    required_features
  File "/usr/src/app/homeassistant/helpers/service.py", line 316, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/app/homeassistant/helpers/service.py", line 337, in _handle_service_platform_call
    await getattr(entity, func)(**data)
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/app/homeassistant/components/plex/media_player.py", line 731, in media_pause
    self.device.pause(self._active_media_plexapi_type)
  File "/usr/local/lib/python3.7/site-packages/plexapi/client.py", line 299, in pause
    self.sendCommand('playback/pause', type=mtype)
  File "/usr/local/lib/python3.7/site-packages/plexapi/client.py", line 195, in sendCommand
    return self.query(key, headers=headers)
  File "/usr/local/lib/python3.7/site-packages/plexapi/client.py", line 165, in query
    raise BadRequest('(%s) %s; %s %s' % (response.status_code, codename, response.url, errtext))
plexapi.exceptions.BadRequest: (406) not_acceptable; http://192.168.1.222:32433/player/playback/pause?commandID=1&type=music 
Hellowlol commented 5 years ago

@ianhyzy what client is this?

ianhyzy commented 5 years ago

@ianhyzy what client is this?

This is with the Plex Home Theater Windows program as a client

Hellowlol commented 5 years ago

@ianhyzy and the ip adress, is that the server or the client?

ianhyzy commented 5 years ago

@ianhyzy and the ip adress, is that the server or the client?

.222 is the client, .201 is the server

stale[bot] commented 5 years ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue now has been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

beville commented 5 years ago

The dep package "plexapi" needs to be upgraded to "3.2.0". That will fix this problem.