Skip to content

Fix compatibility with urllib3-future#784

Merged
amotl merged 1 commit intomainfrom
urllib3-future
Mar 3, 2026
Merged

Fix compatibility with urllib3-future#784
amotl merged 1 commit intomainfrom
urllib3-future

Conversation

@amotl
Copy link
Member

@amotl amotl commented Mar 2, 2026

About

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.

Problem

src/crate/client/http.py:614:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
src/crate/client/http.py:212: in request
    return self.pool.urlopen(
/path/to/site-packages/urllib3/connectionpool.py:1740: in urlopen
    response = self._make_request(  # type: ignore[call-overload,misc]
/path/to/site-packages/urllib3/connectionpool.py:1308: in _make_request
    rp = conn.request(
/path/to/site-packages/urllib3/connection.py:506: in request
    rp = self.endheaders(expect_body_afterward=chunks is not None)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/path/to/site-packages/urllib3/backend/hface.py:1323: in endheaders
    self._protocol.submit_headers(
/path/to/site-packages/urllib3/contrib/hface/protocols/http1/_h11.py:184: in submit_headers
    self._h11_submit(headers_to_request(headers))
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
/path/to/site-packages/urllib3/contrib/hface/protocols/http1/_h11.py:91: in headers_to_request
    return h11.Request(
/path/to/site-packages/h11/_events.py:96: in __init__
    self, "headers", normalize_and_validate(headers, _parsed=_parsed)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/path/to/site-packages/h11/_headers.py:164: in normalize_and_validate
    value = bytesify(value)
            ^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

s = 29

    def bytesify(s: Union[bytes, bytearray, memoryview, int, str]) -> bytes:
        # Fast-path:
        if type(s) is bytes:
            return s
        if isinstance(s, str):
            s = s.encode("ascii")
        if isinstance(s, int):
>           raise TypeError("expected bytes-like object, not int")
E           TypeError: expected bytes-like object, not int

/path/to/site-packages/h11/_util.py:134: TypeError

References

`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.
@amotl
Copy link
Member Author

amotl commented Mar 3, 2026

This has also been swiftly fixed upstream by @Ousret per jawah/urllib3.future@23f2aed. Thanks a stack.

They recommended:

It's preferable that the crate library would properly cast content length value to either str or ascii bytes string regardless of the fix.

So I think the patch is still viable, and will be merged.

@amotl amotl merged commit 9c63a5c into main Mar 3, 2026
16 checks passed
@amotl amotl deleted the urllib3-future branch March 3, 2026 07:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compatibility with urllib3-future: ProgrammingError: expected bytes-like object, not int

2 participants