jawah / niquests

“Safest, Fastest, Easiest, and Most advanced” Python HTTP Client. Production Ready! Drop-in replacement for Requests. HTTP/1.1, HTTP/2, and HTTP/3 supported. With WebSocket!
https://niquests.readthedocs.io/en/latest/
Apache License 2.0
978 stars 22 forks source link

niquests issue with poetry #155

Closed edinhodiluviano closed 2 days ago

edinhodiluviano commented 3 days ago

If niquests and poetry are installed on the same environment, poetry can't add a new library.

Expected Result

When using poetry add pandas, just install pandas...

Actual Result

When using poetry add pandas, we get an opaque write to closed file error message.

Reproduction Steps

Using debian trixie or the python official latest image (python:3.13.0-bookworm):

python3 -m venv .venv
. .venv/bin/activate
pip install poetry
poetry init -n
poetry add niquests
poetry add pandas

System Information

[09:27:58] edinho at edinhopc in ~/test  
$ python3 -m venv .venv
[09:28:09] edinho at edinhopc in ~/test  
$ . .venv/bin/activate
(.venv) [09:28:14] edinho at edinhopc in ~/test  
$ pip install poetry
Collecting poetry
  Using cached poetry-1.8.4-py3-none-any.whl.metadata (6.9 kB)
Collecting build<2.0.0,>=1.0.3 (from poetry)
  Using cached build-1.2.2.post1-py3-none-any.whl.metadata (6.5 kB)
Collecting cachecontrol<0.15.0,>=0.14.0 (from cachecontrol[filecache]<0.15.0,>=0.14.0->poetry)
  Using cached cachecontrol-0.14.0-py3-none-any.whl.metadata (3.1 kB)
Collecting cleo<3.0.0,>=2.1.0 (from poetry)
  Using cached cleo-2.1.0-py3-none-any.whl.metadata (12 kB)
Collecting crashtest<0.5.0,>=0.4.1 (from poetry)
  Using cached crashtest-0.4.1-py3-none-any.whl.metadata (1.1 kB)
Collecting dulwich<0.22.0,>=0.21.2 (from poetry)
  Using cached dulwich-0.21.7-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (4.3 kB)
Collecting fastjsonschema<3.0.0,>=2.18.0 (from poetry)
  Using cached fastjsonschema-2.20.0-py3-none-any.whl.metadata (2.1 kB)
Collecting installer<0.8.0,>=0.7.0 (from poetry)
  Using cached installer-0.7.0-py3-none-any.whl.metadata (936 bytes)
Collecting keyring<25.0.0,>=24.0.0 (from poetry)
  Using cached keyring-24.3.1-py3-none-any.whl.metadata (20 kB)
Collecting packaging>=23.1 (from poetry)
  Using cached packaging-24.1-py3-none-any.whl.metadata (3.2 kB)
Collecting pexpect<5.0.0,>=4.7.0 (from poetry)
  Using cached pexpect-4.9.0-py2.py3-none-any.whl.metadata (2.5 kB)
Collecting pkginfo<2.0,>=1.10 (from poetry)
  Using cached pkginfo-1.11.2-py3-none-any.whl.metadata (11 kB)
Collecting platformdirs<5,>=3.0.0 (from poetry)
  Using cached platformdirs-4.3.6-py3-none-any.whl.metadata (11 kB)
Collecting poetry-core==1.9.1 (from poetry)
  Using cached poetry_core-1.9.1-py3-none-any.whl.metadata (3.5 kB)
Collecting poetry-plugin-export<2.0.0,>=1.6.0 (from poetry)
  Using cached poetry_plugin_export-1.8.0-py3-none-any.whl.metadata (2.8 kB)
Collecting pyproject-hooks<2.0.0,>=1.0.0 (from poetry)
  Using cached pyproject_hooks-1.2.0-py3-none-any.whl.metadata (1.3 kB)
Collecting requests<3.0,>=2.26 (from poetry)
  Using cached requests-2.32.3-py3-none-any.whl.metadata (4.6 kB)
Collecting requests-toolbelt<2.0.0,>=1.0.0 (from poetry)
  Using cached requests_toolbelt-1.0.0-py2.py3-none-any.whl.metadata (14 kB)
Collecting shellingham<2.0,>=1.5 (from poetry)
  Using cached shellingham-1.5.4-py2.py3-none-any.whl.metadata (3.5 kB)
Collecting tomlkit<1.0.0,>=0.11.4 (from poetry)
  Using cached tomlkit-0.13.2-py3-none-any.whl.metadata (2.7 kB)
Collecting trove-classifiers>=2022.5.19 (from poetry)
  Using cached trove_classifiers-2024.10.16-py3-none-any.whl.metadata (2.2 kB)
Collecting virtualenv<21.0.0,>=20.26.6 (from poetry)
  Using cached virtualenv-20.27.0-py3-none-any.whl.metadata (4.5 kB)
Collecting msgpack<2.0.0,>=0.5.2 (from cachecontrol<0.15.0,>=0.14.0->cachecontrol[filecache]<0.15.0,>=0.14.0->poetry)
  Using cached msgpack-1.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (8.4 kB)
Collecting filelock>=3.8.0 (from cachecontrol[filecache]<0.15.0,>=0.14.0->poetry)
  Using cached filelock-3.16.1-py3-none-any.whl.metadata (2.9 kB)
Collecting rapidfuzz<4.0.0,>=3.0.0 (from cleo<3.0.0,>=2.1.0->poetry)
  Using cached rapidfuzz-3.10.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (11 kB)
Collecting urllib3>=1.25 (from dulwich<0.22.0,>=0.21.2->poetry)
  Using cached urllib3-2.2.3-py3-none-any.whl.metadata (6.5 kB)
Collecting jaraco.classes (from keyring<25.0.0,>=24.0.0->poetry)
  Using cached jaraco.classes-3.4.0-py3-none-any.whl.metadata (2.6 kB)
Collecting SecretStorage>=3.2 (from keyring<25.0.0,>=24.0.0->poetry)
  Using cached SecretStorage-3.3.3-py3-none-any.whl.metadata (4.0 kB)
Collecting jeepney>=0.4.2 (from keyring<25.0.0,>=24.0.0->poetry)
  Using cached jeepney-0.8.0-py3-none-any.whl.metadata (1.3 kB)
Collecting ptyprocess>=0.5 (from pexpect<5.0.0,>=4.7.0->poetry)
  Using cached ptyprocess-0.7.0-py2.py3-none-any.whl.metadata (1.3 kB)
Collecting charset-normalizer<4,>=2 (from requests<3.0,>=2.26->poetry)
  Using cached charset_normalizer-3.4.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (34 kB)
Collecting idna<4,>=2.5 (from requests<3.0,>=2.26->poetry)
  Using cached idna-3.10-py3-none-any.whl.metadata (10 kB)
Collecting certifi>=2017.4.17 (from requests<3.0,>=2.26->poetry)
  Using cached certifi-2024.8.30-py3-none-any.whl.metadata (2.2 kB)
Collecting distlib<1,>=0.3.7 (from virtualenv<21.0.0,>=20.26.6->poetry)
  Using cached distlib-0.3.9-py2.py3-none-any.whl.metadata (5.2 kB)
Collecting cryptography>=2.0 (from SecretStorage>=3.2->keyring<25.0.0,>=24.0.0->poetry)
  Using cached cryptography-43.0.3-cp39-abi3-manylinux_2_28_x86_64.whl.metadata (5.4 kB)
Collecting more-itertools (from jaraco.classes->keyring<25.0.0,>=24.0.0->poetry)
  Using cached more_itertools-10.5.0-py3-none-any.whl.metadata (36 kB)
Collecting cffi>=1.12 (from cryptography>=2.0->SecretStorage>=3.2->keyring<25.0.0,>=24.0.0->poetry)
  Using cached cffi-1.17.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (1.5 kB)
Collecting pycparser (from cffi>=1.12->cryptography>=2.0->SecretStorage>=3.2->keyring<25.0.0,>=24.0.0->poetry)
  Using cached pycparser-2.22-py3-none-any.whl.metadata (943 bytes)
Using cached poetry-1.8.4-py3-none-any.whl (249 kB)
Using cached poetry_core-1.9.1-py3-none-any.whl (309 kB)
Using cached build-1.2.2.post1-py3-none-any.whl (22 kB)
Using cached cachecontrol-0.14.0-py3-none-any.whl (22 kB)
Using cached cleo-2.1.0-py3-none-any.whl (78 kB)
Using cached crashtest-0.4.1-py3-none-any.whl (7.6 kB)
Using cached dulwich-0.21.7-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (519 kB)
Using cached fastjsonschema-2.20.0-py3-none-any.whl (23 kB)
Using cached installer-0.7.0-py3-none-any.whl (453 kB)
Using cached keyring-24.3.1-py3-none-any.whl (38 kB)
Using cached packaging-24.1-py3-none-any.whl (53 kB)
Using cached pexpect-4.9.0-py2.py3-none-any.whl (63 kB)
Using cached pkginfo-1.11.2-py3-none-any.whl (31 kB)
Using cached platformdirs-4.3.6-py3-none-any.whl (18 kB)
Using cached poetry_plugin_export-1.8.0-py3-none-any.whl (10 kB)
Using cached pyproject_hooks-1.2.0-py3-none-any.whl (10 kB)
Using cached requests-2.32.3-py3-none-any.whl (64 kB)
Using cached requests_toolbelt-1.0.0-py2.py3-none-any.whl (54 kB)
Using cached shellingham-1.5.4-py2.py3-none-any.whl (9.8 kB)
Using cached tomlkit-0.13.2-py3-none-any.whl (37 kB)
Using cached trove_classifiers-2024.10.16-py3-none-any.whl (13 kB)
Using cached virtualenv-20.27.0-py3-none-any.whl (3.1 MB)
Using cached certifi-2024.8.30-py3-none-any.whl (167 kB)
Using cached charset_normalizer-3.4.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (143 kB)
Using cached distlib-0.3.9-py2.py3-none-any.whl (468 kB)
Using cached filelock-3.16.1-py3-none-any.whl (16 kB)
Using cached idna-3.10-py3-none-any.whl (70 kB)
Using cached jeepney-0.8.0-py3-none-any.whl (48 kB)
Using cached msgpack-1.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (401 kB)
Using cached ptyprocess-0.7.0-py2.py3-none-any.whl (13 kB)
Using cached rapidfuzz-3.10.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.1 MB)
Using cached SecretStorage-3.3.3-py3-none-any.whl (15 kB)
Using cached urllib3-2.2.3-py3-none-any.whl (126 kB)
Using cached jaraco.classes-3.4.0-py3-none-any.whl (6.8 kB)
Using cached cryptography-43.0.3-cp39-abi3-manylinux_2_28_x86_64.whl (4.0 MB)
Using cached more_itertools-10.5.0-py3-none-any.whl (60 kB)
Using cached cffi-1.17.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (479 kB)
Using cached pycparser-2.22-py3-none-any.whl (117 kB)
Installing collected packages: trove-classifiers, ptyprocess, fastjsonschema, distlib, urllib3, tomlkit, shellingham, rapidfuzz, pyproject-hooks, pycparser, poetry-core, platformdirs, pkginfo, pexpect, packaging, msgpack, more-itertools, jeepney, installer, idna, filelock, crashtest, charset-normalizer, certifi, virtualenv, requests, jaraco.classes, dulwich, cleo, cffi, build, requests-toolbelt, cryptography, cachecontrol, SecretStorage, keyring, poetry-plugin-export, poetry
Successfully installed SecretStorage-3.3.3 build-1.2.2.post1 cachecontrol-0.14.0 certifi-2024.8.30 cffi-1.17.1 charset-normalizer-3.4.0 cleo-2.1.0 crashtest-0.4.1 cryptography-43.0.3 distlib-0.3.9 dulwich-0.21.7 fastjsonschema-2.20.0 filelock-3.16.1 idna-3.10 installer-0.7.0 jaraco.classes-3.4.0 jeepney-0.8.0 keyring-24.3.1 more-itertools-10.5.0 msgpack-1.1.0 packaging-24.1 pexpect-4.9.0 pkginfo-1.11.2 platformdirs-4.3.6 poetry-1.8.4 poetry-core-1.9.1 poetry-plugin-export-1.8.0 ptyprocess-0.7.0 pycparser-2.22 pyproject-hooks-1.2.0 rapidfuzz-3.10.0 requests-2.32.3 requests-toolbelt-1.0.0 shellingham-1.5.4 tomlkit-0.13.2 trove-classifiers-2024.10.16 urllib3-2.2.3 virtualenv-20.27.0
(.venv) [09:28:47] edinho at edinhopc in ~/test  
$ poetry init -n
(.venv) [09:28:51] edinho at edinhopc in ~/test  
$ poetry add niquests
Using version ^3.9.1 for niquests

Updating dependencies
Resolving dependencies... (0.2s)

Package operations: 7 installs, 0 updates, 0 removals

  - Installing h11 (0.14.0)
  - Installing jh2 (5.0.3)
  - Installing qh3 (1.2.1)
  - Installing kiss-headers (2.4.3): Installing...
  - Installing urllib3-future (2.10.906): Installing...
  - Installing kiss-headers (2.4.3)
  - Installing urllib3-future (2.10.906): Installing...
  - Installing wassima (1.1.4): Installing...
Installing /home/edinho/test/.venv/lib/python3.12/site-packages/urllib3/_request_methods.py over existing file
Installing /home/edinho/test/.venv/lib/python3.12/site-packages/urllib3/_version.py over existing file
Installing /home/edinho/test/.venv/lib/python3.12/site-packages/urllib3/connection.py over existing file
Installing /home/edinho/test/.venv/lib/python3.12/site-packages/urllib3/connectionpool.py over existing file
Installing /home/edinho/test/.venv/lib/python3.12/site-packages/urllib3/exceptions.py over existing file
Installing /home/edinho/test/.venv/lib/python3.12/site-packages/urllib3/fields.py over existing file
Installing /home/edinho/test/.venv/lib/python3.12/site-packages/urllib3/filepost.py over existing file
Installing /home/edinho/test/.venv/lib/python3.12/site-packages/urllib3/poolmanager.py over existing file
Installing /home/edinho/test/.venv/lib/python3.12/site-packages/urllib3/py.typed over existing file
  - Installing wassima (1.1.4)
Installing /home/edinho/test/.venv/lib/python3.12/site-packages/urllib3/contrib/__init__.py over existing file
Installing /home/edinho/test/.venv/lib/python3.12/site-packages/urllib3/contrib/pyopenssl.py over existing file
Installing /home/edinho/test/.venv/lib/python3.12/site-packages/urllib3/contrib/socks.py over existing file
Installing /home/edinho/test/.venv/lib/python3.12/site-packages/urllib3/contrib/emscripten/__init__.py over existing file
Installing /home/edinho/test/.venv/lib/python3.12/site-packages/urllib3/http2/__init__.py over existing file
Installing /home/edinho/test/.venv/lib/python3.12/site-packages/urllib3/util/__init__.py over existing file
Installing /home/edinho/test/.venv/lib/python3.12/site-packages/urllib3/util/connection.py over existing file
Installing /home/edinho/test/.venv/lib/python3.12/site-packages/urllib3/util/proxy.py over existing file
Installing /home/edinho/test/.venv/lib/python3.12/site-packages/urllib3/util/request.py over existing file
Installing /home/edinho/test/.venv/lib/python3.12/site-packages/urllib3/util/response.py over existing file
Installing /home/edinho/test/.venv/lib/python3.12/site-packages/urllib3/util/retry.py over existing file
Installing /home/edinho/test/.venv/lib/python3.12/site-packages/urllib3/util/ssl_.py over existing file
Installing /home/edinho/test/.venv/lib/python3.12/site-packages/urllib3/util/ssl_match_hostname.py over existing file
Installing /home/edinho/test/.venv/lib/python3.12/site-packages/urllib3/util/ssltransport.py over existing file
Installing /home/edinho/test/.venv/lib/python3.12/site-packages/urllib3/util/timeout.py over existing file
Installing /home/edinho/test/.venv/lib/python3.12/site-packages/urllib3/util/url.py over existing file
  - Installing urllib3-future (2.10.906)
  - Installing wassima (1.1.4)
  - Installing niquests (3.9.1)

Writing lock file
(.venv) [09:28:58] edinho at edinhopc in ~/test  
$ poetry add pandas

write to closed file

Full poetry add pandas -vvv output:

$ poetry add pandas -vvv
Using virtualenv: /home/edinho/test/.venv
Checking if keyring is available
[keyring:keyring.backend] Loading KWallet
[keyring:keyring.backend] Loading SecretService
[keyring:keyring.backend] Loading Windows
[keyring:keyring.backend] Loading chainer
[keyring:keyring.backend] Loading libsecret
[keyring:keyring.backend] Loading macOS
Using keyring backend 'SecretService Keyring'
Creating new session for pypi.org
[urllib3:urllib3.connectionpool] Starting new HTTPS connection (1): pypi.org:443
[urllib3:urllib3.connectionpool] https://pypi.org:443 "GET /simple/pandas/ HTTP/2.0" 200 215654

  Stack trace:

  28  .venv/lib/python3.12/site-packages/cleo/application.py:327 in run
       325│ 
       326│             try:
     → 327│                 exit_code = self._run(io)
       328│             except BrokenPipeError:
       329│                 # If we are piped to another process, it may close early and send a

  27  .venv/lib/python3.12/site-packages/poetry/console/application.py:190 in _run
       188│         self._load_plugins(io)
       189│ 
     → 190│         exit_code: int = super()._run(io)
       191│         return exit_code
       192│ 

  26  .venv/lib/python3.12/site-packages/cleo/application.py:431 in _run
       429│             io.input.interactive(interactive)
       430│ 
     → 431│         exit_code = self._run_command(command, io)
       432│         self._running_command = None
       433│ 

  25  .venv/lib/python3.12/site-packages/cleo/application.py:473 in _run_command
       471│ 
       472│         if error is not None:
     → 473│             raise error
       474│ 
       475│         return terminate_event.exit_code

  24  .venv/lib/python3.12/site-packages/cleo/application.py:457 in _run_command
       455│ 
       456│             if command_event.command_should_run():
     → 457│                 exit_code = command.run(io)
       458│             else:
       459│                 exit_code = ConsoleCommandEvent.RETURN_CODE_DISABLED

  23  .venv/lib/python3.12/site-packages/cleo/commands/base_command.py:117 in run
       115│         io.input.validate()
       116│ 
     → 117│         return self.execute(io) or 0
       118│ 
       119│     def merge_application_definition(self, merge_args: bool = True) -> None:

  22  .venv/lib/python3.12/site-packages/cleo/commands/command.py:61 in execute
        59│ 
        60│         try:
     →  61│             return self.handle()
        62│         except KeyboardInterrupt:
        63│             return 1

  21  .venv/lib/python3.12/site-packages/poetry/console/commands/add.py:164 in handle
       162│             return 0
       163│ 
     → 164│         requirements = self._determine_requirements(
       165│             packages,
       166│             allow_prereleases=self.option("allow-prereleases"),

  20  .venv/lib/python3.12/site-packages/poetry/console/commands/init.py:381 in _determine_requirements
       379│             elif "version" not in requirement:
       380│                 # determine the best version automatically
     → 381│                 name, version = self._find_best_version_for_package(
       382│                     requirement["name"],
       383│                     allow_prereleases=allow_prereleases,

  19  .venv/lib/python3.12/site-packages/poetry/console/commands/init.py:416 in _find_best_version_for_package
       414│ 
       415│         selector = VersionSelector(self._get_pool())
     → 416│         package = selector.find_best_candidate(
       417│             name, required_version, allow_prereleases=allow_prereleases, source=source
       418│         )

  18  .venv/lib/python3.12/site-packages/poetry/version/version_selector.py:37 in find_best_candidate
        35│             },
        36│         )
     →  37│         candidates = self._pool.find_packages(dependency)
        38│         only_prereleases = all(c.version.is_unstable() for c in candidates)
        39│ 

  17  .venv/lib/python3.12/site-packages/poetry/repositories/repository_pool.py:218 in find_packages
       216│             if packages and self.get_priority(repo.name) is Priority.SUPPLEMENTAL:
       217│                 break
     → 218│             packages += repo.find_packages(dependency)
       219│         return packages
       220│ 

  16  .venv/lib/python3.12/site-packages/poetry/repositories/repository.py:40 in find_packages
        38│         constraint = dependency.constraint
        39│         allow_prereleases = dependency.allows_prereleases()
     →  40│         for package in self._find_packages(dependency.name, constraint):
        41│             if package.yanked and not isinstance(constraint, Version):
        42│                 # PEP 592: yanked files are always ignored, unless they are the only

  15  .venv/lib/python3.12/site-packages/poetry/repositories/pypi_repository.py:92 in _find_packages
        90│         """
        91│         try:
     →  92│             json_page = self.get_page(name)
        93│         except PackageNotFound:
        94│             self._log(f"No packages found for {name}", level="debug")

  14  .venv/lib/python3.12/site-packages/poetry/repositories/pypi_repository.py:188 in _get_page
       186│     def _get_page(self, name: NormalizedName) -> SimpleJsonPage:
       187│         source = self._base_url + f"simple/{name}/"
     → 188│         info = self.get_package_info(name)
       189│         return SimpleJsonPage(source, info)
       190│ 

  13  .venv/lib/python3.12/site-packages/poetry/repositories/pypi_repository.py:83 in get_package_info
        81│         or retrieved from the remote server.
        82│         """
     →  83│         return self._get_package_info(name)
        84│ 
        85│     def _find_packages(

  12  .venv/lib/python3.12/site-packages/poetry/repositories/pypi_repository.py:107 in _get_package_info
       105│     def _get_package_info(self, name: NormalizedName) -> dict[str, Any]:
       106│         headers = {"Accept": "application/vnd.pypi.simple.v1+json"}
     → 107│         info = self._get(f"simple/{name}/", headers=headers)
       108│         if info is None:
       109│             raise PackageNotFound(f"Package [{name}] not found.")

  11  .venv/lib/python3.12/site-packages/poetry/repositories/pypi_repository.py:195 in _get
       193│     ) -> dict[str, Any] | None:
       194│         try:
     → 195│             json_response = self.session.get(
       196│                 self._base_url + endpoint,
       197│                 raise_for_status=False,

  10  .venv/lib/python3.12/site-packages/poetry/utils/authenticator.py:267 in get
       265│ 
       266│     def get(self, url: str, **kwargs: Any) -> requests.Response:
     → 267│         return self.request("get", url, **kwargs)
       268│ 
       269│     def head(self, url: str, **kwargs: Any) -> requests.Response:

   9  .venv/lib/python3.12/site-packages/poetry/utils/authenticator.py:238 in request
       236│             is_last_attempt = attempt >= 5
       237│             try:
     → 238│                 resp = session.send(prepared_request, **send_kwargs)
       239│             except (requests.exceptions.ConnectionError, OSError) as e:
       240│                 if is_last_attempt:

   8  .venv/lib/python3.12/site-packages/requests/sessions.py:746 in send
       744│ 
       745│         if not stream:
     → 746│             r.content
       747│ 
       748│         return r

   7  .venv/lib/python3.12/site-packages/requests/models.py:902 in content
        900│                 self._content = None
        901│             else:
     →  902│                 self._content = b"".join(self.iter_content(CONTENT_CHUNK_SIZE)) or b""
        903│ 
        904│         self._content_consumed = True

   6  .venv/lib/python3.12/site-packages/requests/models.py:820 in generate
        818│             if hasattr(self.raw, "stream"):
        819│                 try:
     →  820│                     yield from self.raw.stream(chunk_size, decode_content=True)
        821│                 except ProtocolError as e:
        822│                     raise ChunkedEncodingError(e)

   5  .venv/lib/python3.12/site-packages/urllib3/response.py:975 in stream
        973│             return
        974│         while not is_fp_closed(self._fp) or len(self._decoded_buffer) > 0:
     →  975│             data = self.read(amt=amt, decode_content=decode_content)
        976│ 
        977│             if data:

   4  .venv/lib/python3.12/site-packages/urllib3/response.py:885 in read
        883│             if self._police_officer is not None and not self._police_officer.busy:
        884│                 with self._police_officer.borrow(self):
     →  885│                     data = self._raw_read(amt)
        886│             else:
        887│                 data = self._raw_read(amt)

   3  .venv/lib/python3.12/site-packages/urllib3/response.py:801 in _raw_read
        799│ 
        800│         with self._error_catcher():
     →  801│             data = self._fp_read(amt) if not fp_closed else b""
        802│ 
        803│             # Mocking library often use io.BytesIO

   2  .venv/lib/python3.12/site-packages/urllib3/response.py:786 in _fp_read
        784│         else:
        785│             # StringIO doesn't like amt=None
     →  786│             return self._fp.read(amt) if amt is not None else self._fp.read()
        787│ 
        788│     def _raw_read(

   1  .venv/lib/python3.12/site-packages/cachecontrol/filewrapper.py:102 in read
       100│             # We may be dealing with b'', a sign that things are over:
       101│             # it's passed e.g. after we've already closed self.__buf.
     → 102│             self.__buf.write(data)
       103│         if self.__is_fp_closed():
       104│             self._close()

  ValueError

  write to closed file

  at /usr/lib/python3.12/tempfile.py:638 in func_wrapper
       634│         if hasattr(a, '__call__'):
       635│             func = a
       636│             @_functools.wraps(func)
       637│             def func_wrapper(*args, **kwargs):
    →  638│                 return func(*args, **kwargs)
       639│             # Avoid closing the file as long as the wrapper is alive,
       640│             # see issue #18879.
       641│             func_wrapper._closer = self._closer
       642│             a = func_wrapper
Ousret commented 2 days ago

It is now fixed in https://github.com/jawah/urllib3.future/releases/tag/2.11.900 Feel free to try to reproduce, I did, the bug no longer appear.

Regards,

edinhodiluviano commented 2 days ago

Great! It is working as intended! Thank you @Ousret : )

Btw, this lib is awesome! Congrats to you the the entire team! : )