From cf4a84a8da48c14ebff2048b1a206c030e746523 Mon Sep 17 00:00:00 2001 From: gutsytechster Date: Sat, 25 Apr 2020 13:51:25 +0530 Subject: [PATCH] fix(pip/_internal): Add a generic network exception to be raised --- news/5380.bugfix | 1 + src/pip/_internal/network/utils.py | 6 ++++++ 2 files changed, 7 insertions(+) create mode 100644 news/5380.bugfix diff --git a/news/5380.bugfix b/news/5380.bugfix new file mode 100644 index 00000000000..7e4d202563f --- /dev/null +++ b/news/5380.bugfix @@ -0,0 +1 @@ +Raise user friendly errors on network failures diff --git a/src/pip/_internal/network/utils.py b/src/pip/_internal/network/utils.py index 907b3fed49a..41261d0c1f2 100644 --- a/src/pip/_internal/network/utils.py +++ b/src/pip/_internal/network/utils.py @@ -1,4 +1,5 @@ from pip._vendor.requests.models import CONTENT_CHUNK_SIZE, Response +from pip._vendor.urllib3.exceptions import NewConnectionError, ReadTimeoutError from pip._internal.exceptions import NetworkConnectionError from pip._internal.utils.typing import MYPY_CHECK_RUNNING @@ -95,3 +96,8 @@ def response_chunks(response, chunk_size=CONTENT_CHUNK_SIZE): if not chunk: break yield chunk + except (NewConnectionError, ReadTimeoutError) as exc: + raise NetworkConnectionError( + "Failed to get address for host! Check your network connectivity " + "and DNS settings.\nDetails: {}".format(exc) + )