From a62b6ed619d352af76ef8db38033f6a1316c61b6 Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Mon, 2 Mar 2026 21:12:46 +0100 Subject: [PATCH] Fix compatibility with `urllib3-future` `grafana-client` uses the `niquests` package, which pulls in `urllib3-future` instead of vanilla `urllib3`. There was a subtle incompatibility that prevented to use `crate` and `grafana-client` within the same program. --- CHANGES.rst | 2 ++ src/crate/client/http.py | 2 +- tests/client/test_http.py | 7 ++++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 4c471399..b02c1559 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -12,6 +12,8 @@ Unreleased - Parse path prefixes from server URLs and propagate them to all requests. +- Fixed compatibility with ``urllib3-future``. + 2025/01/30 2.0.0 ================ diff --git a/src/crate/client/http.py b/src/crate/client/http.py index 3d065f38..71f74c0c 100644 --- a/src/crate/client/http.py +++ b/src/crate/client/http.py @@ -187,7 +187,7 @@ def request( if "Content-Length" not in headers: length = super_len(data) if length is not None: - headers["Content-Length"] = length + headers["Content-Length"] = str(length) # Authentication credentials if username is not None: diff --git a/tests/client/test_http.py b/tests/client/test_http.py index 0292b661..d96ba765 100644 --- a/tests/client/test_http.py +++ b/tests/client/test_http.py @@ -192,7 +192,12 @@ def test_redirect_handling(): # - https://github.com/crate/crate-python/issues/179 # - https://github.com/crate/crate-python/issues/180 - assert client.server_pool["http://localhost:4201"].pool.conn_kw == { + # Remove some optional server pool parameters added by `urllib3-future`. + conn_kw = client.server_pool["http://localhost:4201"].pool.conn_kw + conn_kw.pop("keepalive_delay", None) + conn_kw.pop("resolver", None) + + assert conn_kw == { "socket_options": _get_socket_opts(keepalive=True) }