ws-ephemeral icon indicating copy to clipboard operation
ws-ephemeral copied to clipboard

Failed to connect to qbittorrent Error

Open vtruong68 opened this issue 1 year ago • 11 comments

I regularly get an error when the ephemeral port needs to be renewed. The only way to fix it is to manually restart the container for the port automation to grab a new port and update qbittorrent.

I've tried to set VERIFY_WEBUI_CERTIFICATE=False and PYTHON_QBITTORRENTAPI_DO_NOT_VERIFY_WEBUI_CERTIFICATE to some non-null value as environment variables in my binhex-qbittorrentvpn container, but it doesn't seem to work (I don't think this is the right place to set this, but I couldn't find anywhere else to do this online).

Here's the log:

    return self.sslsocket_class._create(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/ssl.py", line 1075, in _create
    self.do_handshake()
  File "/usr/local/lib/python3.11/ssl.py", line 1346, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLEOFError: [SSL: UNEXPECTED_EOF_WHILE_READING] EOF occurred in violation of protocol (_ssl.c:1002)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/urllib3/connectionpool.py", line 790, in urlopen
    response = self._make_request(
               ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/urllib3/connectionpool.py", line 491, in _make_request
    raise new_e
urllib3.exceptions.SSLError: [SSL: UNEXPECTED_EOF_WHILE_READING] EOF occurred in violation of protocol (_ssl.c:1002)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/requests/adapters.py", line 486, in send
    resp = conn.urlopen(
           ^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/urllib3/connectionpool.py", line 874, in urlopen
    return self.urlopen(
           ^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/urllib3/connectionpool.py", line 844, in urlopen
    retries = retries.increment(
              ^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/urllib3/util/retry.py", line 515, in increment
    raise MaxRetryError(_pool, url, reason) from reason  # type: ignore[arg-type]
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='192.168.1.12', port=8080): Max retries exceeded with url: /api/v2/app/webapiVersion (Caused by SSLError(SSLEOFError(8, '[SSL: UNEXPECTED_EOF_WHILE_READING] EOF occurred in violation of protocol (_ssl.c:1002)')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/qbittorrentapi/request.py", line 465, in _request_manager
    return self._request(
           ^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/qbittorrentapi/request.py", line 531, in _request
    response = self._session.request(
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/qbittorrentapi/request.py", line 678, in request
    return super(QbittorrentSession, self).request(method, url, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/requests/sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/requests/sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/requests/adapters.py", line 517, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='192.168.1.12', port=8080): Max retries exceeded with url: /api/v2/app/webapiVersion (Caused by SSLError(SSLEOFError(8, '[SSL: UNEXPECTED_EOF_WHILE_READING] EOF occurred in violation of protocol (_ssl.c:1002)')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/app/util.py", line 19, in wrapper
    return job_func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/run.py", line 44, in main
    qbit = QbitManager(
           ^^^^^^^^^^^^
  File "/app/lib/qbit.py", line 23, in __init__
    raise e
  File "/app/lib/qbit.py", line 20, in __init__
    self.api = Version.parse(self.client.app_web_api_version())
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/qbittorrentapi/decorators.py", line 91, in wrapper
    return func(client, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/qbittorrentapi/app.py", line 145, in app_web_api_version
    return self._MOCK_WEB_API_VERSION or self._get(
                                         ^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/qbittorrentapi/request.py", line 354, in _get
    return self._request_manager(
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/qbittorrentapi/request.py", line 489, in _request_manager
    raise APIConnectionError(error_message, response=response)
qbittorrentapi.exceptions.APIConnectionError: Failed to connect to qBittorrent. This is likely due to using an untrusted certificate (likely self-signed) for HTTPS qBittorrent WebUI. To suppress this error (and skip certificate verification consequently exposing the HTTPS connection to man-in-the-middle attacks), set VERIFY_WEBUI_CERTIFICATE=False when instantiating Client or set environment variable PYTHON_QBITTORRENTAPI_DO_NOT_VERIFY_WEBUI_CERTIFICATE to a non-null value. SSL Error: SSLError(MaxRetryError("HTTPSConnectionPool(host='192.168.1.12', port=8080): Max retries exceeded with url: /api/v2/app/webapiVersion (Caused by SSLError(SSLEOFError(8, '[SSL: UNEXPECTED_EOF_WHILE_READING] EOF occurred in violation of protocol (_ssl.c:1002)')))"))

vtruong68 avatar Sep 15 '23 17:09 vtruong68

In normal browser are you able to access qBittorrent instance over host='192.168.1.12', port=8080?

Is it actually https (secure) connection? I don't think it would be, can you double check that part please.

What version of qBitTorrent are you using?

dhruvinsh avatar Sep 15 '23 21:09 dhruvinsh

I'm able to access it but it's not a secure connection (only HTTP).

I'm on qbittorrent 4.5.4.

Is there a way to make it secure or bypass the error with a local address? I do have a reverse proxy https address that's like https://qbit.xyz.com that I can use instead in the environment variables if that's the problem, but I'd rather not have to do that when the qbittorrent instance is on the same network.

vtruong68 avatar Sep 15 '23 22:09 vtruong68

you can definitely give the reverse proxy a try,

QBIT_HOST=https://qbit.xyz.com
QBIT_PORT=443

Also do check that both docker container are on the same network (not behind VPN). Try opening console on ws-ephemeral and ping the qbittorrent IP address.

dhruvinsh avatar Sep 16 '23 23:09 dhruvinsh

I double checked and they're on the same network in my unraid setup. I even pinged the qbittorrent address from the ws-ephemeral container and I'm getting a response. I still think it's a little weird that ws-ephemeral always works initially when I restart its container but keeps failing during weekly renewals. Does that seem unusual to you too?

vtruong68 avatar Sep 17 '23 03:09 vtruong68

it is unusual, assuming you are running latest version of the docker image (v2.1.0) by default port reset occurs at every 6 day at 2:00 AM (I haven't expose the ability change to user yet).

During this time, is any of your service under go any maintenance or get turned off?

dhruvinsh avatar Sep 18 '23 00:09 dhruvinsh

I'm definitely on the latest docker image (v2.1.0) and I don't have any maintenance activities that occur at 2 AM on any day.

vtruong68 avatar Sep 18 '23 02:09 vtruong68

Just pushed a new version (v2.2.0), if possible give that a try.

dhruvinsh avatar Sep 20 '23 00:09 dhruvinsh

Sure! Just updated. I'll revert to the local address/port (192.168.1.12:8080) in the environment variables and check to see if it renews without error in a week or so.

vtruong68 avatar Sep 20 '23 03:09 vtruong68

It seems to be renewing the port now without erroring out. I'll reopen if I encounter any other issues.

Thanks!

vtruong68 avatar Sep 27 '23 21:09 vtruong68

Just noticed it errored out again though with a different error message upon renewing on v2.3.0. I'm on qbittorrent v4.5.5.

    return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/ssl.py", line 517, in wrap_socket
    return self.sslsocket_class._create(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/ssl.py", line 1108, in _create
    self.do_handshake()
  File "/usr/local/lib/python3.11/ssl.py", line 1379, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLEOFError: [SSL: UNEXPECTED_EOF_WHILE_READING] EOF occurred in violation of protocol (_ssl.c:1006)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/urllib3/connectionpool.py", line 790, in urlopen
    response = self._make_request(
               ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/urllib3/connectionpool.py", line 491, in _make_request
    raise new_e
urllib3.exceptions.SSLError: [SSL: UNEXPECTED_EOF_WHILE_READING] EOF occurred in violation of protocol (_ssl.c:1006)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/requests/adapters.py", line 486, in send
    resp = conn.urlopen(
           ^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/urllib3/connectionpool.py", line 874, in urlopen
    return self.urlopen(
           ^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/urllib3/connectionpool.py", line 844, in urlopen
    retries = retries.increment(
              ^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/urllib3/util/retry.py", line 515, in increment
    raise MaxRetryError(_pool, url, reason) from reason  # type: ignore[arg-type]
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='192.168.1.12', port=8080): Max retries exceeded with url: /api/v2/app/webapiVersion (Caused by SSLError(SSLEOFError(8, '[SSL: UNEXPECTED_EOF_WHILE_READING] EOF occurred in violation of protocol (_ssl.c:1006)')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/qbittorrentapi/request.py", line 465, in _request_manager
    return self._request(
           ^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/qbittorrentapi/request.py", line 531, in _request
    response = self._session.request(
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/qbittorrentapi/request.py", line 678, in request
    return super(QbittorrentSession, self).request(method, url, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/requests/sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/requests/sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/requests/adapters.py", line 517, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='192.168.1.12', port=8080): Max retries exceeded with url: /api/v2/app/webapiVersion (Caused by SSLError(SSLEOFError(8, '[SSL: UNEXPECTED_EOF_WHILE_READING] EOF occurred in violation of protocol (_ssl.c:1006)')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/app/util.py", line 19, in wrapper
    return job_func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/run.py", line 51, in main
    qbit = QbitManager(
           ^^^^^^^^^^^^
  File "/app/lib/qbit.py", line 23, in __init__
    raise e
  File "/app/lib/qbit.py", line 20, in __init__
    self.api = Version.parse(self.client.app_web_api_version())
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/qbittorrentapi/decorators.py", line 91, in wrapper
    return func(client, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/qbittorrentapi/app.py", line 181, in app_web_api_version
    return self._MOCK_WEB_API_VERSION or self._get(
                                         ^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/qbittorrentapi/request.py", line 354, in _get
    return self._request_manager(
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/qbittorrentapi/request.py", line 489, in _request_manager
    raise APIConnectionError(error_message, response=response)
qbittorrentapi.exceptions.APIConnectionError: Failed to connect to qBittorrent. This is likely due to using an untrusted certificate (likely self-signed) for HTTPS qBittorrent WebUI. To suppress this error (and skip certificate verification consequently exposing the HTTPS connection to man-in-the-middle attacks), set VERIFY_WEBUI_CERTIFICATE=False when instantiating Client or set environment variable PYTHON_QBITTORRENTAPI_DO_NOT_VERIFY_WEBUI_CERTIFICATE to a non-null value. SSL Error: SSLError(MaxRetryError("HTTPSConnectionPool(host='192.168.1.12', port=8080): Max retries exceeded with url: /api/v2/app/webapiVersion (Caused by SSLError(SSLEOFError(8, '[SSL: UNEXPECTED_EOF_WHILE_READING] EOF occurred in violation of protocol (_ssl.c:1006)')))"))

2023-09-28 20:11:06,285:   ERROR: QbitManager: cannot work with qbit.
2023-09-28 20:11:06,285:   ERROR:        root: Something wrong with Qbit, it's not accessible
2023-09-28 20:11:06,285:    INFO:        main: Schedule is setup to run every 6 day at 02:00

vtruong68 avatar Oct 02 '23 20:10 vtruong68

Hey at this point nothing much can be done from my side. Everything is pointing to the network issue between docker to docker.

dhruvinsh avatar Oct 15 '23 00:10 dhruvinsh