jawah / niquests

“Safest, Fastest, Easiest, and Most advanced” Python HTTP Client. Production Ready! Drop-in replacement for Requests. HTTP/1.1, HTTP/2, and HTTP/3 supported. With WebSocket!
https://niquests.readthedocs.io/en/latest/
Apache License 2.0
1.05k stars 23 forks source link

Error: Can't handle event type ConnectionClosed when role=SERVER and state=SEND_RESPONSE #161

Closed glensc closed 1 month ago

glensc commented 1 month ago

Refs

Expected Result

Actual Result

Error and trace

``` 2024-10-21 19:16:55,413 DEBUG[plexapi]:GET https://redacted.plex.direct:32400/library/sections/8/all?includeCollections=0&type=4&X-Plex-Container-Size=0&X-Plex-Container-Start=0 2024-10-21 19:16:55,417 ERROR[plextraktsync.cli]:can't handle event type ConnectionClosed when role=SERVER and state=SEND_RESPONSE Traceback (most recent call last): File "python-3.9/lib/python3.9/site-packages/niquests/adapters.py", line 941, in send resp_or_promise = conn.urlopen( # type: ignore[call-overload,misc] File "python-3.9/lib/python3.9/site-packages/urllib3/connectionpool.py", line 1698, in urlopen retries = retries.increment( File "python-3.9/lib/python3.9/site-packages/urllib3/util/retry.py", line 499, in increment raise reraise(type(error), error, _stacktrace) File "python-3.9/lib/python3.9/site-packages/urllib3/util/util.py", line 39, in reraise raise value File "python-3.9/lib/python3.9/site-packages/urllib3/connectionpool.py", line 1619, in urlopen response = self._make_request( # type: ignore[call-overload,misc] File "python-3.9/lib/python3.9/site-packages/urllib3/connectionpool.py", line 1263, in _make_request response = conn.getresponse( File "python-3.9/lib/python3.9/site-packages/urllib3/connection.py", line 596, in getresponse low_response = super().getresponse( File "python-3.9/lib/python3.9/site-packages/urllib3/backend/hface.py", line 1364, in getresponse head_event: HeadersReceived | EarlyHeadersReceived = self.__exchange_until( # type: ignore[assignment] File "python-3.9/lib/python3.9/site-packages/urllib3/backend/hface.py", line 961, in __exchange_until raise ProtocolError(event.message) urllib3.exceptions.ProtocolError: can't handle event type ConnectionClosed when role=SERVER and state=SEND_RESPONSE During handling of the above exception, another exception occurred: Traceback (most recent call last): File "plextraktsync/cli.py", line 28, in wrap cmd(*args, **kwargs) File "plextraktsync/commands/sync.py", line 74, in sync run_async(runner, walker=w, dry_run=config.dry_run) File "python-3.9/lib/python3.9/site-packages/decorator.py", line 232, in fun return caller(func, *(extras + args), **kw) File "plextraktsync/decorators/coro.py", line 15, in coro return asyncio.run(f(*args, **kwargs)) File "/opt/homebrew/Cellar/python@3.9/3.9.20/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/runners.py", line 44, in run return loop.run_until_complete(main) File "/opt/homebrew/Cellar/python@3.9/3.9.20/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 647, in run_until_complete return future.result() File "plextraktsync/commands/sync.py", line 13, in run_async await runner.sync(**kwargs) File "plextraktsync/sync/Sync.py", line 52, in sync async for episode in walker.find_episodes(): File "plextraktsync/plan/Walker.py", line 134, in find_episodes async for ep in self.episodes_from_sections(self.plan.show_sections): File "plextraktsync/plan/Walker.py", line 185, in episodes_from_sections async for m in it: File "plextraktsync/plan/Walker.py", line 204, in progressbar pb = self._progressbar(iterable, **kwargs) File "plextraktsync/rich/RichProgressBar.py", line 11, in __init__ total = len(iterable) File "plextraktsync/plex/PlexSectionPager.py", line 22, in __len__ return self.total_size File "/opt/homebrew/Cellar/python@3.9/3.9.20/Frameworks/Python.framework/Versions/3.9/lib/python3.9/functools.py", line 993, in __get__ val = self.func(instance) File "plextraktsync/plex/PlexSectionPager.py", line 26, in total_size return self.section.totalViewSize(libtype=self.libtype, includeCollections=False) File "python-3.9/lib/python3.9/site-packages/plexapi/library.py", line 528, in totalViewSize data = self._server.query(part) File "python-3.9/lib/python3.9/site-packages/plexapi/server.py", line 760, in query response = method(url, headers=headers, params=params, timeout=timeout, **kwargs) File "python-3.9/lib/python3.9/site-packages/requests_cache/session.py", line 127, in get return self.request('GET', url, params=params, **kwargs) File "python-3.9/lib/python3.9/site-packages/requests_cache/session.py", line 183, in request return super().request(method, url, *args, headers=headers, **kwargs) # type: ignore File "python-3.9/lib/python3.9/site-packages/niquests/sessions.py", line 563, in request resp = self.send(prep, **send_kwargs) File "python-3.9/lib/python3.9/site-packages/requests_cache/session.py", line 230, in send response = self._send_and_cache(request, actions, cached_response, **kwargs) File "python-3.9/lib/python3.9/site-packages/requests_cache/session.py", line 254, in _send_and_cache response = super().send(request, **kwargs) File "python-3.9/lib/python3.9/site-packages/niquests/sessions.py", line 1223, in send r = adapter.send(request, **kwargs) File "python-3.9/lib/python3.9/site-packages/niquests/adapters.py", line 978, in send raise ConnectionError(err, request=request) niquests.exceptions.ConnectionError: can't handle event type ConnectionClosed when role=SERVER and state=SEND_RESPONSE ```

Reproduction Steps

So far it has happened only once, not sure how to reproduce.

System Information

$ python -m niquests.help
```json { "charset_normalizer": { "version": "3.4.0" }, "http1": { "h11": "0.14.0" }, "http2": { "jh2": "5.0.3" }, "http3": { "enabled": true, "qh3": "1.2.1" }, "idna": { "version": "3.10" }, "implementation": { "name": "CPython", "version": "3.9.20" }, "niquests": { "version": "3.10.0" }, "ocsp": { "enabled": true }, "platform": { "release": "23.6.0", "system": "Darwin" }, "system_ssl": { "version": "30300020" }, "urllib3.future": { "cohabitation_version": null, "version": "2.11.901" }, "wassima": { "certifi_fallback": false, "enabled": true, "version": "1.1.4" } } ```
Ousret commented 1 month ago

It is fixed via linked PR.

regards,

glensc commented 1 month ago

Super! I hope this is last one :)

Altho I have noticed some stuck state, i.e nothing is happening (nothing in logs and progressbar stops), but I have not confirmed it's due switching libraries yet.