pypa / pip

The Python package installer
https://pip.pypa.io/
MIT License
9.52k stars 3.02k forks source link

Improve exception raised on corrupted gzip response #9653

Open fuchanghao opened 3 years ago

fuchanghao commented 3 years ago

pip version

21.0.1

Python version

3.8.8

OS

Windows 10 20H2

Additional information

No response

Description

I did "pip list" which works fine But it cause error when I use "pip list -o" But If I update some packages which work fine. like "pip install youtube-dl you-get -U",

Looking in indexes: https://mirrors.aliyun.com/pypi/simple/ Requirement already satisfied: youtube-dl in c:\program files\python3\lib\site-packages (2021.2.10) Collecting youtube-dl Downloading https://mirrors.aliyun.com/pypi/packages/4e/fe/8d11d7a778633441efa68f1a0bd5fbfcd79e31cb0ef7f20acb8d5c4498db/youtube_dl-2021.2.22-py2.py3-none-any.whl (1.9 MB) |████████████████████████████████| 1.9 MB ... Requirement already satisfied: you-get in c:\program files\python3\lib\site-packages (0.4.1500) Installing collected packages: youtube-dl Attempting uninstall: youtube-dl Found existing installation: youtube-dl 2021.2.10 Uninstalling youtube-dl-2021.2.10: Successfully uninstalled youtube-dl-2021.2.10 Successfully installed youtube-dl-2021.2.22

Expected behavior

List all packages that are outdated

How to Reproduce

  1. install python 3.8.8 amd64 from https://www.python.org/downloads/release/python-388/
  2. Then run 'pip list -o' in PowerShell 7.1.2.
  3. An error occurs.

Output

ERROR: Exception: Traceback (most recent call last): File "c:\program files\python3\lib\site-packages\pip_vendor\urllib3\response.py", line 401, in _decode data = self._decoder.decompress(data) File "c:\program files\python3\lib\site-packages\pip_vendor\urllib3\response.py", line 88, in decompress ret += self._obj.decompress(data) zlib.error: Error -3 while decompressing data: incorrect header check

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "c:\program files\python3\lib\site-packages\pip_vendor\requests\models.py", line 753, in generate for chunk in self.raw.stream(chunk_size, decode_content=True): File "c:\program files\python3\lib\site-packages\pip_vendor\urllib3\response.py", line 576, in stream data = self.read(amt=amt, decode_content=decode_content) File "c:\program files\python3\lib\site-packages\pip_vendor\urllib3\response.py", line 548, in read data = self._decode(data, decode_content, flush_decoder) File "c:\program files\python3\lib\site-packages\pip_vendor\urllib3\response.py", line 404, in _decode raise DecodeError( pip._vendor.urllib3.exceptions.DecodeError: ('Received response with content-encoding: gzip, but failed to decode it.', error('Error -3 while decompressing data: incorrect header check'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "c:\program files\python3\lib\site-packages\pip_internal\cli\base_command.py", line 189, in _main status = self.run(options, args) File "c:\program files\python3\lib\site-packages\pip_internal\commands\list.py", line 169, in run packages = self.get_outdated(packages, options) File "c:\program files\python3\lib\site-packages\pip_internal\commands\list.py", line 178, in get_outdated return [ File "c:\program files\python3\lib\site-packages\pip_internal\commands\list.py", line 178, in return [ File "c:\program files\python3\lib\site-packages\pip_internal\commands\list.py", line 231, in iter_packages_latest_infos for dist in map_multithread(latest_info, packages): File "c:\program files\python3\lib\multiprocessing\pool.py", line 868, in next raise value File "c:\program files\python3\lib\multiprocessing\pool.py", line 125, in worker result = (True, func(args, kwds)) File "c:\program files\python3\lib\site-packages\pip_internal\commands\list.py", line 208, in latest_info all_candidates = finder.find_all_candidates(dist.key) File "c:\program files\python3\lib\site-packages\pip_internal\index\package_finder.py", line 815, in find_all_candidates package_links = self.process_project_url( File "c:\program files\python3\lib\site-packages\pip_internal\index\package_finder.py", line 779, in process_project_url html_page = self._link_collector.fetch_page(project_url) File "c:\program files\python3\lib\site-packages\pip_internal\index\collector.py", line 617, in fetch_page return _get_html_page(location, session=self.session) File "c:\program files\python3\lib\site-packages\pip_internal\index\collector.py", line 429, in _get_html_page resp = _get_html_response(url, session=session) File "c:\program files\python3\lib\site-packages\pip_internal\index\collector.py", line 126, in _get_html_response resp = session.get( File "c:\program files\python3\lib\site-packages\pip_vendor\requests\sessions.py", line 555, in get return self.request('GET', url, kwargs) File "c:\program files\python3\lib\site-packages\pip_internal\network\session.py", line 424, in request return super().request(method, url, args, kwargs) File "c:\program files\python3\lib\site-packages\pip_vendor\requests\sessions.py", line 542, in request resp = self.send(prep, send_kwargs) File "c:\program files\python3\lib\site-packages\pip_vendor\requests\sessions.py", line 697, in send r.content File "c:\program files\python3\lib\site-packages\pip_vendor\requests\models.py", line 831, in content self._content = b''.join(self.iter_content(CONTENT_CHUNK_SIZE)) or b'' File "c:\program files\python3\lib\site-packages\pip_vendor\requests\models.py", line 758, in generate raise ContentDecodingError(e) pip._vendor.requests.exceptions.ContentDecodingError: ('Received response with content-encoding: gzip, but failed to decode it.', error('Error -3 while decompressing data: incorrect header check'))

Code of Conduct

uranusjr commented 3 years ago

Looks like a connection issue to your index (aliyun?). You need to talk to either your network provider (maybe they are mangling your gzip requests) or aliyun admins (maybe they are mis-handling the gzip requests). Either way, there is little pip can do here, except maybe emitting a better error message saying the network request is corrupted.