Skip to content

Commit 221f4a8

Browse files
authored
fix: add missing packaging dependency for feature requiring urllib3 (#1732)
1 parent 9f7d3fa commit 221f4a8

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

google/auth/transport/urllib3.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,21 @@
3434
try:
3535
import urllib3 # type: ignore
3636
import urllib3.exceptions # type: ignore
37+
from packaging import version # type: ignore
3738
except ImportError as caught_exc: # pragma: NO COVER
3839
raise ImportError(
39-
"The urllib3 library is not installed from please install the "
40-
"urllib3 package to use the urllib3 transport."
40+
""
41+
f"Error: {caught_exc}."
42+
" The 'google-auth' library requires the extras installed "
43+
"for urllib3 network transport."
44+
"\n"
45+
"Please install the necessary dependencies using pip:\n"
46+
" pip install google-auth[urllib3]\n"
47+
"\n"
48+
"(Note: Using '[urllib3]' ensures the specific dependencies needed for this feature are installed. "
49+
"We recommend running this command in your virtual environment.)"
4150
) from caught_exc
4251

43-
from packaging import version # type: ignore
4452

4553
from google.auth import environment_vars
4654
from google.auth import exceptions
@@ -414,7 +422,7 @@ def urlopen(self, method, url, body=None, headers=None, **kwargs):
414422
body=body,
415423
headers=headers,
416424
_credential_refresh_attempt=_credential_refresh_attempt + 1,
417-
**kwargs
425+
**kwargs,
418426
)
419427

420428
return response

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"reauth": "pyu2f>=0.1.5",
3535
"enterprise_cert": ["cryptography", "pyopenssl"],
3636
"pyjwt": ["pyjwt>=2.0", "cryptography>=38.0.3"],
37+
"urllib3": ["urllib3", "packaging"],
3738
}
3839

3940
with io.open("README.rst", "r") as fh:

system_tests/secrets.tar.enc

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)