Skip to content

Calling c.events() seems to break my python script sometimes #647

@ShawkMusic

Description

@ShawkMusic

When I run a python script that uses caldav (more details below), the script freezes for like a minute or two and then I get this error:

Traceback (most recent call last):
  File "/nix/store/n3a01p8l886s3v5n4x7frg52y3hppnfs-python3-3.13.12-env/lib/python3.13/site-packages/urllib3_future/response.py", line 668, in _error_catcher
    yield
  File "/nix/store/n3a01p8l886s3v5n4x7frg52y3hppnfs-python3-3.13.12-env/lib/python3.13/site-packages/urllib3_future/response.py", line 771, in _raw_read
    data = self._fp_read(amt) if not fp_closed else b""
           ~~~~~~~~~~~~~^^^^^
  File "/nix/store/n3a01p8l886s3v5n4x7frg52y3hppnfs-python3-3.13.12-env/lib/python3.13/site-packages/urllib3_future/response.py", line 756, in _fp_read
    return self._fp.read(amt) if amt is not None else self._fp.read()
                                                      ~~~~~~~~~~~~~^^
  File "/nix/store/n3a01p8l886s3v5n4x7frg52y3hppnfs-python3-3.13.12-env/lib/python3.13/site-packages/urllib3_future/backend/_base.py", line 342, in read
    data, self._eot, self.trailers = self.__internal_read_st(
                                     ~~~~~~~~~~~~~~~~~~~~~~~^
        __size, self._stream_id
        ^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/nix/store/n3a01p8l886s3v5n4x7frg52y3hppnfs-python3-3.13.12-env/lib/python3.13/site-packages/urllib3_future/backend/hface.py", line 1544, in __read_st
    events: list[DataReceived | HeadersReceived] = self.__exchange_until(  # type: ignore[assignment]
                                                   ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        DataReceived,
        ^^^^^^^^^^^^^
    ...<5 lines>...
        respect_end_stream_signal=__respect_end_signal,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/nix/store/n3a01p8l886s3v5n4x7frg52y3hppnfs-python3-3.13.12-env/lib/python3.13/site-packages/urllib3_future/backend/hface.py", line 945, in __exchange_until
    data_in = sync_recv_gro(self.sock, self.blocksize)
  File "/nix/store/n3a01p8l886s3v5n4x7frg52y3hppnfs-python3-3.13.12-env/lib/python3.13/site-packages/urllib3_future/contrib/ssa/_gro.py", line 88, in sync_recv_gro
    data, ancdata, _flags, addr = sock.recvmsg(bufsize, ancbufsize)
                                  ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
TimeoutError: timed out

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

Traceback (most recent call last):
  File "/nix/store/n3a01p8l886s3v5n4x7frg52y3hppnfs-python3-3.13.12-env/lib/python3.13/site-packages/niquests/models.py", line 1436, in content
    self._content = self.raw.read(decode_content=True)  # type: ignore[arg-type]
                    ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/n3a01p8l886s3v5n4x7frg52y3hppnfs-python3-3.13.12-env/lib/python3.13/site-packages/urllib3_future/response.py", line 884, in read
    data = self._raw_read(amt)
  File "/nix/store/n3a01p8l886s3v5n4x7frg52y3hppnfs-python3-3.13.12-env/lib/python3.13/site-packages/urllib3_future/response.py", line 770, in _raw_read
    with self._error_catcher():
         ~~~~~~~~~~~~~~~~~~~^^
  File "/nix/store/n3a01p8l886s3v5n4x7frg52y3hppnfs-python3-3.13.12-env/lib/python3.13/contextlib.py", line 162, in __exit__
    self.gen.throw(value)
    ~~~~~~~~~~~~~~^^^^^^^
  File "/nix/store/n3a01p8l886s3v5n4x7frg52y3hppnfs-python3-3.13.12-env/lib/python3.13/site-packages/urllib3_future/response.py", line 673, in _error_catcher
    raise ReadTimeoutError(self._pool, None, "Read timed out.") from e  # type: ignore[arg-type]
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
urllib3_future.exceptions.ReadTimeoutError: None: Read timed out.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File [REDACTED (path to python script running the code)], line 296, in <module>
    for event in c.events():
                 ~~~~~~~~^^
  File "/nix/store/n3a01p8l886s3v5n4x7frg52y3hppnfs-python3-3.13.12-env/lib/python3.13/site-packages/caldav/collection.py", line 1116, in events
    return self.search(comp_class=Event)
           ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
  File "/nix/store/n3a01p8l886s3v5n4x7frg52y3hppnfs-python3-3.13.12-env/lib/python3.13/site-packages/caldav/collection.py", line 965, in search
    return my_searcher.search(
           ~~~~~~~~~~~~~~~~~~^
        self, server_expand, split_expanded, props, xml, post_filter, _hacks
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/nix/store/n3a01p8l886s3v5n4x7frg52y3hppnfs-python3-3.13.12-env/lib/python3.13/site-packages/caldav/search.py", line 480, in search
    (response, objects) = calendar._request_report_build_resultlist(
                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        xml, self.comp_class, props=props
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/nix/store/n3a01p8l886s3v5n4x7frg52y3hppnfs-python3-3.13.12-env/lib/python3.13/site-packages/caldav/collection.py", line 784, in _request_report_build_resultlist
    response = self._query(xml, 1, "report")
  File "/nix/store/n3a01p8l886s3v5n4x7frg52y3hppnfs-python3-3.13.12-env/lib/python3.13/site-packages/caldav/davobject.py", line 219, in _query
    ret = getattr(self.client, query_method)(url, body, depth)
  File "/nix/store/n3a01p8l886s3v5n4x7frg52y3hppnfs-python3-3.13.12-env/lib/python3.13/site-packages/caldav/davclient.py", line 873, in report
    return self.request(
           ~~~~~~~~~~~~^
        url,
        ^^^^
    ...<2 lines>...
        {"Depth": str(depth), "Content-Type": 'application/xml; charset="utf-8"'},
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/nix/store/n3a01p8l886s3v5n4x7frg52y3hppnfs-python3-3.13.12-env/lib/python3.13/site-packages/caldav/davclient.py", line 1034, in request
    log.debug("server responded with %i %s" % (r.status_code, r.reason))
                                               ^^^^^^^^^^^^^
  File "/nix/store/n3a01p8l886s3v5n4x7frg52y3hppnfs-python3-3.13.12-env/lib/python3.13/site-packages/niquests/models.py", line 1049, in __getattribute__
    super().__getattribute__("_gather")()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/nix/store/n3a01p8l886s3v5n4x7frg52y3hppnfs-python3-3.13.12-env/lib/python3.13/site-packages/niquests/models.py", line 1035, in _gather
    super().__getattribute__("connection").gather(self)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/nix/store/n3a01p8l886s3v5n4x7frg52y3hppnfs-python3-3.13.12-env/lib/python3.13/site-packages/niquests/adapters.py", line 1315, in gather
    next_resp = self._future_handler(response, low_resp)
  File "/nix/store/n3a01p8l886s3v5n4x7frg52y3hppnfs-python3-3.13.12-env/lib/python3.13/site-packages/niquests/adapters.py", line 1148, in _future_handler
    response.content
  File "/nix/store/n3a01p8l886s3v5n4x7frg52y3hppnfs-python3-3.13.12-env/lib/python3.13/site-packages/niquests/models.py", line 1053, in __getattribute__
    return super().__getattribute__(item)
           ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/nix/store/n3a01p8l886s3v5n4x7frg52y3hppnfs-python3-3.13.12-env/lib/python3.13/site-packages/niquests/models.py", line 1444, in content
    raise ConnectionError(e)
niquests.exceptions.ConnectionError: None: Read timed out.

Trying to run a minimal reproduction on the python shell gives me this:

>>> with caldav.DAVClient(
...         url="[REDACTED]",
...         username="[REDACTED]",
...         password="[REDACTED]",
...     ) as client:
...         my_principal = client.principal()
...         calendars = my_principal.calendars()
...         
...         for c in calendars:
...             if c.url == "[REDACTED]":
...                 for event in c.events():
...                     print("bruh")
...                     

Traceback (most recent call last):
  File "/nix/store/n3a01p8l886s3v5n4x7frg52y3hppnfs-python3-3.13.12-env/lib/python3.13/site-packages/urllib3_future/response.py", line 668, in _error_catcher
    yield
  File "/nix/store/n3a01p8l886s3v5n4x7frg52y3hppnfs-python3-3.13.12-env/lib/python3.13/site-packages/urllib3_future/response.py", line 771, in _raw_read
    data = self._fp_read(amt) if not fp_closed else b""
           ~~~~~~~~~~~~~^^^^^
  File "/nix/store/n3a01p8l886s3v5n4x7frg52y3hppnfs-python3-3.13.12-env/lib/python3.13/site-packages/urllib3_future/response.py", line 756, in _fp_read
    return self._fp.read(amt) if amt is not None else self._fp.read()
                                                      ~~~~~~~~~~~~~^^
  File "/nix/store/n3a01p8l886s3v5n4x7frg52y3hppnfs-python3-3.13.12-env/lib/python3.13/site-packages/urllib3_future/backend/_base.py", line 342, in read
    data, self._eot, self.trailers = self.__internal_read_st(
                                     ~~~~~~~~~~~~~~~~~~~~~~~^
        __size, self._stream_id
        ^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/nix/store/n3a01p8l886s3v5n4x7frg52y3hppnfs-python3-3.13.12-env/lib/python3.13/site-packages/urllib3_future/backend/hface.py", line 1544, in __read_st
    events: list[DataReceived | HeadersReceived] = self.__exchange_until(  # type: ignore[assignment]
                                                   ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        DataReceived,
        ^^^^^^^^^^^^^
    ...<5 lines>...
        respect_end_stream_signal=__respect_end_signal,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/nix/store/n3a01p8l886s3v5n4x7frg52y3hppnfs-python3-3.13.12-env/lib/python3.13/site-packages/urllib3_future/backend/hface.py", line 945, in __exchange_until
    data_in = sync_recv_gro(self.sock, self.blocksize)
  File "/nix/store/n3a01p8l886s3v5n4x7frg52y3hppnfs-python3-3.13.12-env/lib/python3.13/site-packages/urllib3_future/contrib/ssa/_gro.py", line 88, in sync_recv_gro
    data, ancdata, _flags, addr = sock.recvmsg(bufsize, ancbufsize)
                                  ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
TimeoutError: timed out

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

Traceback (most recent call last):
  File "/nix/store/n3a01p8l886s3v5n4x7frg52y3hppnfs-python3-3.13.12-env/lib/python3.13/site-packages/niquests/models.py", line 1436, in content
    self._content = self.raw.read(decode_content=True)  # type: ignore[arg-type]
                    ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/n3a01p8l886s3v5n4x7frg52y3hppnfs-python3-3.13.12-env/lib/python3.13/site-packages/urllib3_future/response.py", line 884, in read
    data = self._raw_read(amt)
  File "/nix/store/n3a01p8l886s3v5n4x7frg52y3hppnfs-python3-3.13.12-env/lib/python3.13/site-packages/urllib3_future/response.py", line 770, in _raw_read
    with self._error_catcher():
         ~~~~~~~~~~~~~~~~~~~^^
  File "/nix/store/n3a01p8l886s3v5n4x7frg52y3hppnfs-python3-3.13.12-env/lib/python3.13/contextlib.py", line 162, in __exit__
    self.gen.throw(value)
    ~~~~~~~~~~~~~~^^^^^^^
  File "/nix/store/n3a01p8l886s3v5n4x7frg52y3hppnfs-python3-3.13.12-env/lib/python3.13/site-packages/urllib3_future/response.py", line 673, in _error_catcher
    raise ReadTimeoutError(self._pool, None, "Read timed out.") from e  # type: ignore[arg-type]
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
urllib3_future.exceptions.ReadTimeoutError: None: Read timed out.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<python-input-11>", line 14, in <module>
    for event in c.events():
                 ~~~~~~~~^^
  File "/nix/store/n3a01p8l886s3v5n4x7frg52y3hppnfs-python3-3.13.12-env/lib/python3.13/site-packages/caldav/collection.py", line 1116, in events
    return self.search(comp_class=Event)
           ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
  File "/nix/store/n3a01p8l886s3v5n4x7frg52y3hppnfs-python3-3.13.12-env/lib/python3.13/site-packages/caldav/collection.py", line 965, in search
    return my_searcher.search(
           ~~~~~~~~~~~~~~~~~~^
        self, server_expand, split_expanded, props, xml, post_filter, _hacks
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/nix/store/n3a01p8l886s3v5n4x7frg52y3hppnfs-python3-3.13.12-env/lib/python3.13/site-packages/caldav/search.py", line 480, in search
    (response, objects) = calendar._request_report_build_resultlist(
                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        xml, self.comp_class, props=props
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/nix/store/n3a01p8l886s3v5n4x7frg52y3hppnfs-python3-3.13.12-env/lib/python3.13/site-packages/caldav/collection.py", line 784, in _request_report_build_resultlist
    response = self._query(xml, 1, "report")
  File "/nix/store/n3a01p8l886s3v5n4x7frg52y3hppnfs-python3-3.13.12-env/lib/python3.13/site-packages/caldav/davobject.py", line 219, in _query
    ret = getattr(self.client, query_method)(url, body, depth)
  File "/nix/store/n3a01p8l886s3v5n4x7frg52y3hppnfs-python3-3.13.12-env/lib/python3.13/site-packages/caldav/davclient.py", line 873, in report
    return self.request(
           ~~~~~~~~~~~~^
        url,
        ^^^^
    ...<2 lines>...
        {"Depth": str(depth), "Content-Type": 'application/xml; charset="utf-8"'},
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/nix/store/n3a01p8l886s3v5n4x7frg52y3hppnfs-python3-3.13.12-env/lib/python3.13/site-packages/caldav/davclient.py", line 1034, in request
    log.debug("server responded with %i %s" % (r.status_code, r.reason))
                                               ^^^^^^^^^^^^^
  File "/nix/store/n3a01p8l886s3v5n4x7frg52y3hppnfs-python3-3.13.12-env/lib/python3.13/site-packages/niquests/models.py", line 1049, in __getattribute__
    super().__getattribute__("_gather")()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/nix/store/n3a01p8l886s3v5n4x7frg52y3hppnfs-python3-3.13.12-env/lib/python3.13/site-packages/niquests/models.py", line 1035, in _gather
    super().__getattribute__("connection").gather(self)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/nix/store/n3a01p8l886s3v5n4x7frg52y3hppnfs-python3-3.13.12-env/lib/python3.13/site-packages/niquests/adapters.py", line 1315, in gather
    next_resp = self._future_handler(response, low_resp)
  File "/nix/store/n3a01p8l886s3v5n4x7frg52y3hppnfs-python3-3.13.12-env/lib/python3.13/site-packages/niquests/adapters.py", line 1148, in _future_handler
    response.content
  File "/nix/store/n3a01p8l886s3v5n4x7frg52y3hppnfs-python3-3.13.12-env/lib/python3.13/site-packages/niquests/models.py", line 1053, in __getattribute__
    return super().__getattribute__(item)
           ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/nix/store/n3a01p8l886s3v5n4x7frg52y3hppnfs-python3-3.13.12-env/lib/python3.13/site-packages/niquests/models.py", line 1444, in content
    raise ConnectionError(e)

If I remove the line for event in c.events():, it works just fine

>>> with caldav.DAVClient(
...         url="[REDACTED]",
...         username="[REDACTED]",
...         password="[REDACTED]",
...     ) as client:
...         my_principal = client.principal()
...         calendars = my_principal.calendars()
...         
...         for c in calendars:
...             if c.url == "[REDACTED]":
...                 print("bruh")
...                 
bruh

There doesn't seem to be a difference if I link to different calendars either.
Puzzlingly, sometimes it just decides it wants to work once in a while even with the for event in c.events(): line, so I have no idea what's really going on, but including the for event in c.events(): seems to be the thing that most consistently makes it break, as far as I can tell.

I'm using NixOS 26.05

Metadata

Metadata

Assignees

No one assigned

    Labels

    need-feedbackNothing will be done without more info/feedback from someone that can reproduce the issue

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions