aaronsegura/nextcloud-async

Nexcloud Talk [408] Request timed out exception

Vdauphin opened this issue · 2 comments

Hello!
I recently discover this library and it looks really promising!

I am sending message to a discussion in Nextcloud Talk. Each time I receive it without issue, but I still have an exception occurring each time:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/anyio/streams/tls.py", line 131, in _call_sslobject_method
    result = func(*args)
  File "/usr/lib/python3.10/ssl.py", line 917, in read
    v = self._sslobj.read(len)
ssl.SSLWantReadError: The operation did not complete (read) (_ssl.c:2578)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/httpcore/_backends/anyio.py", line 34, in read
    return await self._stream.receive(max_bytes=max_bytes)
  File "/usr/local/lib/python3.10/dist-packages/anyio/streams/tls.py", line 196, in receive
    data = await self._call_sslobject_method(self._ssl_object.read, max_bytes)
  File "/usr/local/lib/python3.10/dist-packages/anyio/streams/tls.py", line 138, in _call_sslobject_method
    data = await self.transport_stream.receive()
  File "/usr/local/lib/python3.10/dist-packages/anyio/_backends/_asyncio.py", line 1203, in receive
    await self._protocol.read_event.wait()
  File "/usr/lib/python3.10/asyncio/locks.py", line 214, in wait
    await fut
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/httpcore/_exceptions.py", line 10, in map_exceptions
    yield
  File "/usr/local/lib/python3.10/dist-packages/httpcore/_backends/anyio.py", line 32, in read
    with anyio.fail_after(timeout):
  File "/usr/local/lib/python3.10/dist-packages/anyio/_core/_tasks.py", line 119, in __exit__
    raise TimeoutError
TimeoutError

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

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/httpx/_transports/default.py", line 60, in map_httpcore_exceptions
    yield
  File "/usr/local/lib/python3.10/dist-packages/httpx/_transports/default.py", line 353, in handle_async_request
    resp = await self._pool.handle_async_request(req)
  File "/usr/local/lib/python3.10/dist-packages/httpcore/_async/connection_pool.py", line 262, in handle_async_request
    raise exc
  File "/usr/local/lib/python3.10/dist-packages/httpcore/_async/connection_pool.py", line 245, in handle_async_request
    response = await connection.handle_async_request(request)
  File "/usr/local/lib/python3.10/dist-packages/httpcore/_async/connection.py", line 96, in handle_async_request
    return await self._connection.handle_async_request(request)
  File "/usr/local/lib/python3.10/dist-packages/httpcore/_async/http11.py", line 121, in handle_async_request
    raise exc
  File "/usr/local/lib/python3.10/dist-packages/httpcore/_async/http11.py", line 99, in handle_async_request
    ) = await self._receive_response_headers(**kwargs)
  File "/usr/local/lib/python3.10/dist-packages/httpcore/_async/http11.py", line 164, in _receive_response_headers
    event = await self._receive_event(timeout=timeout)
  File "/usr/local/lib/python3.10/dist-packages/httpcore/_async/http11.py", line 200, in _receive_event
    data = await self._network_stream.read(
  File "/usr/local/lib/python3.10/dist-packages/httpcore/_backends/anyio.py", line 31, in read
    with map_exceptions(exc_map):
  File "/usr/lib/python3.10/contextlib.py", line 153, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/usr/local/lib/python3.10/dist-packages/httpcore/_exceptions.py", line 14, in map_exceptions
    raise to_exc(exc) from exc
httpcore.ReadTimeout

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

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/nextcloud_async/api/__init__.py", line 91, in request
    response = await self.client.request(
  File "/usr/local/lib/python3.10/dist-packages/httpx/_client.py", line 1530, in request
    return await self.send(request, auth=auth, follow_redirects=follow_redirects)
  File "/usr/local/lib/python3.10/dist-packages/httpx/_client.py", line 1617, in send
    response = await self._send_handling_auth(
  File "/usr/local/lib/python3.10/dist-packages/httpx/_client.py", line 1645, in _send_handling_auth
    response = await self._send_handling_redirects(
  File "/usr/local/lib/python3.10/dist-packages/httpx/_client.py", line 1682, in _send_handling_redirects
    response = await self._send_single_request(request)
  File "/usr/local/lib/python3.10/dist-packages/httpx/_client.py", line 1719, in _send_single_request
    response = await transport.handle_async_request(request)
  File "/usr/local/lib/python3.10/dist-packages/httpx/_transports/default.py", line 352, in handle_async_request
    with map_httpcore_exceptions():
  File "/usr/lib/python3.10/contextlib.py", line 153, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/usr/local/lib/python3.10/dist-packages/httpx/_transports/default.py", line 77, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.ReadTimeout

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/xbee/reception/module/nextcloud.py", line 50, in send
    await asyncio.gather(task)
  File "/usr/local/lib/python3.10/dist-packages/nextcloud_async/api/ocs/talk/__init__.py", line 644, in send_to_conversation
    response = await self.ocs_query(
  File "/usr/local/lib/python3.10/dist-packages/nextcloud_async/api/ocs/__init__.py", line 75, in ocs_query
    response = await self.request(
  File "/usr/local/lib/python3.10/dist-packages/nextcloud_async/api/__init__.py", line 98, in request
    raise NextCloudRequestTimeout()
nextcloud_async.exceptions.NextCloudRequestTimeout: [408] Request timed out.

I have a lot of code but basically here is a simple code showing the context:

async def send(
        message,
        silent = False
    ):
    task = nca.send_to_conversation(
        "k3jhkljjh",
        message,
        silent = silent
    )
    await asyncio.gather(task)

async def main():
    while True:
        if whenTrue:
            send("🚪🔓!")

loop = asyncio.get_event_loop()
try:
    loop.run_until_complete(main())
finally:
    loop.close()

Do you have some input how I can avoid this error? Or how I could understand what is going wrong?
Cheers

Hello!

I'm not sure this is related to the library. Perhaps you need to increase the timeout in your httpx.AsyncClient?

httpx.AsyncClient(timeout=30)

I have mine set to 30 by default.

Thank you for your feedback

I'm not sure this is related to the library

Base on this, I investigated again more on the Nextcloud side and when I created a new discussion (almost the same, same name etc), the issue has gone
Not sure what I have done in this conversation to reach a time out
I will monitor this in case it happen again