encode / httpx

A next generation HTTP client for Python. 🦋
https://www.python-httpx.org/
BSD 3-Clause "New" or "Revised" License
13.28k stars 844 forks source link

Missing urllib3 import #1051

Closed andredias closed 4 years ago

andredias commented 4 years ago

Since I updated from httpx 0.12.1 to 0.13.3 I get the error invalid module name: 'urllib3.exceptions'. I suspect it is specifically related to httpx because of this difference in poetry.lock, which shows that urllib3 is not a dependency anymore:

@@ -113,18 +101,16 @@
 name = "httpx"
 optional = false
 python-versions = ">=3.6"
-version = "0.12.1"
+version = "0.13.3"

 [package.dependencies]
 certifi = "*"
 chardet = ">=3.0.0,<4.0.0"
-h11 = ">=0.8,<0.10"
-h2 = ">=3.0.0,<4.0.0"
 hstspreload = "*"
+httpcore = ">=0.9.0,<0.10.0"
 idna = ">=2.0.0,<3.0.0"
 rfc3986 = ">=1.3,<2"
-sniffio = ">=1.0.0,<2.0.0"
-urllib3 = ">=1.0.0,<2.0.0"
+sniffio = "*"

This is the error I got:

Traceback (most recent call last):
  File "/home/andre/projetos/pronus/invoice/server/.venv/bin/pytest", line 10, in <module>
    sys.exit(main())
  File "/home/andre/projetos/pronus/invoice/server/.venv/lib/python3.8/site-packages/_pytest/config/__init__.py", line 124, in main
    ret = config.hook.pytest_cmdline_main(
  File "/home/andre/projetos/pronus/invoice/server/.venv/lib/python3.8/site-packages/pluggy/hooks.py", line 286, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "/home/andre/projetos/pronus/invoice/server/.venv/lib/python3.8/site-packages/pluggy/manager.py", line 93, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/home/andre/projetos/pronus/invoice/server/.venv/lib/python3.8/site-packages/pluggy/manager.py", line 84, in <lambda>
    self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
  File "/home/andre/projetos/pronus/invoice/server/.venv/lib/python3.8/site-packages/pluggy/callers.py", line 208, in _multicall
    return outcome.get_result()
  File "/home/andre/projetos/pronus/invoice/server/.venv/lib/python3.8/site-packages/pluggy/callers.py", line 80, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/home/andre/projetos/pronus/invoice/server/.venv/lib/python3.8/site-packages/pluggy/callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "/home/andre/projetos/pronus/invoice/server/.venv/lib/python3.8/site-packages/_pytest/main.py", line 240, in pytest_cmdline_main
    return wrap_session(config, _main)
  File "/home/andre/projetos/pronus/invoice/server/.venv/lib/python3.8/site-packages/_pytest/main.py", line 228, in wrap_session
    config.hook.pytest_sessionfinish(
  File "/home/andre/projetos/pronus/invoice/server/.venv/lib/python3.8/site-packages/pluggy/hooks.py", line 286, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "/home/andre/projetos/pronus/invoice/server/.venv/lib/python3.8/site-packages/pluggy/manager.py", line 93, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/home/andre/projetos/pronus/invoice/server/.venv/lib/python3.8/site-packages/pluggy/manager.py", line 84, in <lambda>
    self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
  File "/home/andre/projetos/pronus/invoice/server/.venv/lib/python3.8/site-packages/pluggy/callers.py", line 203, in _multicall
    gen.send(outcome)
  File "/home/andre/projetos/pronus/invoice/server/.venv/lib/python3.8/site-packages/_pytest/terminal.py", line 717, in pytest_sessionfinish
    outcome.get_result()
  File "/home/andre/projetos/pronus/invoice/server/.venv/lib/python3.8/site-packages/pluggy/callers.py", line 80, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/home/andre/projetos/pronus/invoice/server/.venv/lib/python3.8/site-packages/pluggy/callers.py", line 182, in _multicall
    next(gen)  # first yield
  File "/home/andre/projetos/pronus/invoice/server/.venv/lib/python3.8/site-packages/_pytest/warnings.py", line 142, in pytest_sessionfinish
    with catch_warnings_for_item(
  File "/usr/lib/python3.8/contextlib.py", line 113, in __enter__
    return next(self.gen)
  File "/home/andre/projetos/pronus/invoice/server/.venv/lib/python3.8/site-packages/_pytest/warnings.py", line 82, in catch_warnings_for_item
    _setoption(warnings, arg)
  File "/home/andre/projetos/pronus/invoice/server/.venv/lib/python3.8/site-packages/_pytest/warnings.py", line 21, in _setoption
    category = wmod._getcategory(category)
  File "/usr/lib/python3.8/warnings.py", line 262, in _getcategory
    raise _OptionError("invalid module name: %r" % (module,)) from None
warnings._OptionError: invalid module name: 'urllib3.exceptions'
Makefile:11: recipe for target 'test' failed

The problem seems to be related to the fixture discovering phase of pytest. Unfortunately, I don't have additional information besides that. The conftest.py I'm using is:

from typing import AsyncIterable

from httpx import AsyncClient
from pytest import fixture

@fixture
async def client() -> AsyncIterable[AsyncClient]:
    async with AsyncClient(base_url='https://localhost', verify=False, http2=True) as client:
        yield client

to reproduce the error, just run pytest --fixtures

Environment

Regards,

André

florimondmanca commented 4 years ago

Hi,

Can you nuke the pytest cache and/or recreate your venu and see if that resolves it?

urllib3 indeed became an optional dependency in 0.13 since we are now using our own networking code for the sync API. It’s possible that’s not been properly picked up by your tooling. As a matter of fact I can’t reproduce this myself (the fixture works just fine).

andredias commented 4 years ago

You're right. It was a problem with cache. Sorry for the trouble.