Plex intergration: Plex server could not be reached: %s", server_config[CONF_URL]

Hello, I’m trying to setup the new plex intergration, I’m using my WAN URL which i can access both on LAN and lets say for testing on LTE via mobile, so it works. I’ve authorized and logged in on plex.tv. But i get the following error:

hu Oct 17 2019 19:13:04 GMT+0200 (Central European Summer Time)
Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 672, in urlopen
    chunked=chunked,
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 421, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 416, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/local/lib/python3.7/http/client.py", line 1336, in getresponse
    response.begin()
  File "/usr/local/lib/python3.7/http/client.py", line 306, in begin
    version, status, reason = self._read_status()
  File "/usr/local/lib/python3.7/http/client.py", line 275, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 720, in urlopen
    method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
  File "/usr/local/lib/python3.7/site-packages/urllib3/util/retry.py", line 400, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/usr/local/lib/python3.7/site-packages/urllib3/packages/six.py", line 734, in reraise
    raise value.with_traceback(tb)
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 672, in urlopen
    chunked=chunked,
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 421, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 416, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/local/lib/python3.7/http/client.py", line 1336, in getresponse
    response.begin()
  File "/usr/local/lib/python3.7/http/client.py", line 306, in begin
    version, status, reason = self._read_status()
  File "/usr/local/lib/python3.7/http/client.py", line 275, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/plex/config_flow.py", line 84, in async_step_server_validate
    await self.hass.async_add_executor_job(plex_server.connect)
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/plex/server.py", line 79, in connect
    _connect_with_url()
  File "/usr/src/homeassistant/homeassistant/components/plex/server.py", line 73, in _connect_with_url
    self._url, self._token, session
  File "/usr/local/lib/python3.7/site-packages/plexapi/server.py", line 102, in __init__
    data = self.query(self.key, timeout=timeout)
  File "/usr/local/lib/python3.7/site-packages/plexapi/server.py", line 341, in query
    response = method(url, headers=headers, timeout=timeout, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 546, in get
    return self.request('GET', url, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 498, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_protocol.py", line 418, in start
    resp = await task
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_app.py", line 458, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_middlewares.py", line 119, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/real_ip.py", line 40, in real_ip_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 73, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 231, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 128, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 164, in post
    return await super().post(request, flow_id)
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 48, in wrapper
    result = await method(view, request, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 90, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 89, in async_configure
    result = await self._async_handle_step(flow, cur_step["step_id"], user_input)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 132, in _async_handle_step
    result: Dict = await getattr(flow, method)(user_input)
  File "/usr/src/homeassistant/homeassistant/components/plex/config_flow.py", line 141, in async_step_select_server
    return await self.async_step_server_validate(config)
  File "/usr/src/homeassistant/homeassistant/components/plex/config_flow.py", line 93, in async_step_server_validate
    "Plex server could not be reached: %s", server_config[CONF_URL]
KeyError: 'url'

Any advise?

Use the local address

Not really what i’m looking for because i want to use SSL, have it set on forced on the server side.

Plex server log:

Oct 17, 2019 20:42:59.946 [0x80c5ee500] DEBUG - Request: [192.168.x.x:35032] rejected because secure connections are required

Plex config:

plex:
  token: !secret plex_token
  host: !secret plex_host
  ssl: true
  verify_ssl: false
  media_player:
    use_episode_art: true
    show_all_controls: true

Thats weird isnt it?

Edit:

After a reboot off HA i see this, which is even more strange:

Oct 17, 2019 21:15:04.962 [0x80c5ee500] DEBUG - Request: [192.168.x.x:32916 (WAN)] GET / (8 live) TLS GZIP Signed-in Token ()
Oct 17, 2019 21:15:04.962 [0x80c5ee500] DEBUG - Completed: [192.168.x.x:32916] 401 GET / (8 live) TLS GZIP 0ms 435 bytes
Oct 17, 2019 21:15:22.553 [0x80c5ee500] DEBUG - Request: [192.168.x.x:33374 (WAN)] GET /library/sections/all (9 live) TLS GZIP Signed-in Token ()
Oct 17, 2019 21:15:22.553 [0x80c5ee500] DEBUG - Completed: [192.168.x.x:33374] 401 GET /library/sections/all (9 live) TLS GZIP 0ms 357 bytes

Original issue might be related to this recent fix: https://github.com/home-assistant/home-assistant/issues/27515. Forcing SSL causes the error based on a bad assumption on my part, sorry.

Dang thats nice, was pulling my hair out haha. It said it should use the link provided by plex so specifying it would not work, after the initial setup? I want to use a local domain with SSL or the plex direct url since i have not opened a port.

Should work in HA q 100.3?

Thank you very much

Yeah, it should be included in 0.100.3.

It should still work if you specify manually, but in 0.100.3 it will use the proper hostname to allow the cert to be fully validated.

Hmm, i’ve did this all via manual config. Then it shows up @ the integration page, then i authorize, select the server and get the error.

Can you try with 0.100.3 and let me know the results?

.101.0b0 Works! Thanks

1 Like