JurajNyiri / PlexMeetsHomeAssistant

Custom card which integrates plex into Home Assistant and makes it possible to launch movies or tv shows on TV with a simple click
Apache License 2.0
107 stars 8 forks source link

Can't play to Plex Media Player running on Windows 10, even with Machine ID setup #32

Closed nathanmfast closed 2 years ago

nathanmfast commented 2 years ago

I was able to follow the "Machine ID setup" on Detailed configuration instructions for end devices to connect to Plex running in a browser on my desktop and start playing shows on it, but when I try to do the same for the entry I have for the instance of "Plex Media Player" I have running on that same desktop, I get an error:

Failed to call service rest_command/pmha_playmedia. Service not found.

Trying to dig a littler, I found that one of the network calls came back with: image

<?xml version='1.0' encoding='utf-8'?>
<Response code="2000" status="HTTPError: ">
  <Traceback>Traceback (most recent call last):
  File "C:\Program Files (x86)\Plex\Plex Media Server\Resources\Plug-ins-1a38e63c6\Framework.bundle\Contents\Resources\Versions\2\Python\Framework\components\runtime.py", line 843, in handle_request
    result = f(**d)
  File "C:\Program Files (x86)\Plex\Plex Media Server\Resources\Plug-ins-1a38e63c6\System.bundle\Contents\Code\playerservice.py", line 38, in process_remote_command
    headers=Request.Headers)
  File "C:\Program Files (x86)\Plex\Plex Media Server\Resources\Plug-ins-1a38e63c6\Framework.bundle\Contents\Resources\Versions\2\Python\Framework\api\networkkit.py", line 194, in Request
    method=method,
  File "C:\Program Files (x86)\Plex\Plex Media Server\Resources\Plug-ins-1a38e63c6\Framework.bundle\Contents\Resources\Versions\2\Python\Framework\api\networkkit.py", line 67, in _http_request
    req = self._core.networking.http_request(url, *args, **kwargs)
  File "C:\Program Files (x86)\Plex\Plex Media Server\Resources\Plug-ins-1a38e63c6\Framework.bundle\Contents\Resources\Versions\2\Python\Framework\components\networking.py", line 346, in http_request
    return HTTPRequest(self._core, url, data, h, url_cache, encoding, errors, timeout, immediate, sleep, opener, follow_redirects, method)
  File "C:\Program Files (x86)\Plex\Plex Media Server\Resources\Plug-ins-1a38e63c6\Framework.bundle\Contents\Resources\Versions\2\Python\Framework\components\networking.py", line 118, in __init__
    self.load()
  File "C:\Program Files (x86)\Plex\Plex Media Server\Resources\Plug-ins-1a38e63c6\Framework.bundle\Contents\Resources\Versions\2\Python\Framework\components\networking.py", line 158, in load
    f = self._opener.open(req, timeout=self._timeout)
  File "C:\Program Files (x86)\Plex\Plex Media Server\python27.zip\urllib2.py", line 435, in open
    response = meth(req, response)
  File "C:\Program Files (x86)\Plex\Plex Media Server\python27.zip\urllib2.py", line 548, in http_response
    'http', request, response, code, msg, hdrs)
  File "C:\Program Files (x86)\Plex\Plex Media Server\python27.zip\urllib2.py", line 473, in error
    return self._call_chain(*args)
  File "C:\Program Files (x86)\Plex\Plex Media Server\python27.zip\urllib2.py", line 407, in _call_chain
    result = func(*args)
  File "C:\Program Files (x86)\Plex\Plex Media Server\python27.zip\urllib2.py", line 556, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error 406: Not Acceptable
</Traceback>
</Response>
JurajNyiri commented 2 years ago

Hey!

I need to document this, this is an undocumented workaround for some issues that were fixed long time ago.

                    await this.hass.callService('rest_command', 'pmha_playmedia', {
                    // eslint-disable-next-line @typescript-eslint/camelcase
                    url,
                    // eslint-disable-next-line @typescript-eslint/camelcase
                    target_client_identifier: machineID,
                    // eslint-disable-next-line @typescript-eslint/camelcase
                    client_identifier: 'PlexMeetsHomeAssistant'
                });

It is called when the usual request from card to plex server fails. You can create a rest_command:

rest_command:
  pmha_playmedia:
    url: "{{ url }}"
    headers:
      X-Plex-Target-Client-Identifier: "{{ target_client_identifier }}"
      X-Plex-Client-Identifier: "{{ client_identifier }}"

in your config and restart. I am 99.9% sure that it will not help as that just does the same thing card does, but from Home Assistant instead (can ignore http vs https issues).

Issue is most probably somewhere else - most probably play device not being available at that time.

First thing to try is using UI editor to set up the card. That does resolve a lot of possible human errors.

JurajNyiri commented 2 years ago

If you want to dig further, try to look into playQueues requests, those should give you more information as to what went wrong.

nathanmfast commented 2 years ago

Do I paste it in just like that? Or is there a url / target_client_identifier / client_identifier I need to plug in? I tried this and it made the error message go away but the show doesn't play on the specified player when I click the play button.

JurajNyiri commented 2 years ago

Is that error coming from Plex itself and not Home Assistant?

If its coming from Home Assistant:

  1. Configure a new card by using UI configurator only, this will prevent most of human errors.
  2. Reopen this issue by filling out the bug template. Please make sure to provide all up to date information in there.
nathanmfast commented 2 years ago

I configured using the UI configurator and got what I believe is the same error: image

I can't tell if this is coming from Plex or Home Assistant. I'll create a proper ticket for it but without knowing where its coming from I'm not sure if I should or not. How could I tell? It seems to be coming from Plex, but maybe it's an issue with url for the request?

If I select the web player for Plex it works, but if I select Plex Media Player it does not.

Also, I'm on https for plex but only http for Home Assistant, but if that matters I'm not sure why it doesn't for the web player. I just noticed questions about this in the bug template so thought I'd add that info. Also your suggestion earlier involved adding something to configuration.yaml so that ignore http vs https issues. I copy/pasted that exactly as-is into the configuration.yaml. To be clear earlier, the "Failed to call service rest_command/pmha_playmedia. Service not found." error message in the UI went away, but network call failed identically before/after that configuration change.

JurajNyiri commented 2 years ago

It looks like it's coming from Plex. I haven't seen an error like this before, usually when there is an error plex just returns 400 or 500 and logs error internally into log.

https plex and http Home Asssistant is fine. The other way is the issue, so no problem there.

The error gone away after pasting into configuration.yaml because now the service exists, but it does the same request which errors out now too.

You could try checking plex logs... in troubleshooting section you can download them. See if there is something that would tell us more 🤔