h2non/pook

pook broken in urllib3>=2

wimglenn opened this issue · 0 comments

reproducer:

import pook
import urllib3

@pook.on
def test_my_api():
    mock = pook.post('https://example.org', reply=200)
    http = urllib3.PoolManager(headers={'User-Agent': 'foo'})
    resp = http.request('POST', 'https://example.org')
    assert resp.status == 200
    assert mock.calls == 1

in urllib3<2, test passes, in urllib3>=2:

=========================================================== FAILURES ============================================================
__________________________________________________________ test_my_api __________________________________________________________

    @pook.on
    def test_my_api():
        mock = pook.post('https://example.org', reply=200)
        http = urllib3.PoolManager(headers={'User-Agent': 'foo'})
>       resp = http.request('POST', 'https://example.org')

test_thing.py:8: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.venv/lib/python3.11/site-packages/urllib3/_request_methods.py:118: in request
    return self.request_encode_body(
.venv/lib/python3.11/site-packages/urllib3/_request_methods.py:217: in request_encode_body
    return self.urlopen(method, url, **extra_kw)
.venv/lib/python3.11/site-packages/urllib3/poolmanager.py:443: in urlopen
    response = conn.urlopen(method, u.request_uri, **kw)
.venv/lib/python3.11/site-packages/pook/interceptors/urllib3.py:184: in handler
    return self._on_request(urlopen, path, conn, method, url,
.venv/lib/python3.11/site-packages/pook/interceptors/urllib3.py:122: in _on_request
    real_headers = dict(headers or {})
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <[TypeError('sequence item 0: expected str instance, bool found') raised in repr()] HTTPHeaderDict object at 0x10b2cca50>
key = '__urllib3_bypass__'

    def __getitem__(self, key: str) -> str:
        val = self._container[key.lower()]
>       return ", ".join(val[1:])
E       TypeError: sequence item 0: expected str instance, bool found

.venv/lib/python3.11/site-packages/urllib3/_collections.py:259: TypeError
==================================================== short test summary info ====================================================
FAILED test_thing.py::test_my_api - TypeError: sequence item 0: expected str instance, bool found
======================================================= 1 failed in 0.12s =======================================================