Search code examples
python-3.xpipopensslipv6timeoutexception

Pip with broken connection: "connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out."


I'm trying to install a package (any package) with pip on Ubuntu 18.04 as well as Ubuntu 20.04. However, I end up with the following error message:

$ pip install --upgrade pip
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) 
after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443):
Read timed out. (read timeout=15)")': /simple/pip/
...

This is what I tried and what didn't work:

  • increasing the timeout
  • changing proxy and/or index server
  • reinstalling all of python
  • reinstalling openssl (plus messing around with it)
  • thinking that the host server was on some blacklist at my service provider up to opening and explicitly allowing ports 443 and 80 with ufw
  • upgrading the OS (from ubuntu 18.04 to 20.04) up to reinstalling the whole OS.
  • Installing Anaconda

Solution

  • I eventually scanned through this one below, that although it's for Windows it actually worked on Ubuntu linux too!!

    Pip ReadTimeoutError in Windows 10

    and the way to fix it is then simply disable ipv6 with the following commands, and done!

    $ sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1
    $ sudo sysctl -w net.ipv6.conf.default.disable_ipv6=1