Skip to content
This repository was archived by the owner on Mar 6, 2026. It is now read-only.

Commit b9101e3

Browse files
author
Jon Wayne Parrott
authored
Add helpful error messages when importing optional dependencies (#125)
1 parent 8170194 commit b9101e3

4 files changed

Lines changed: 24 additions & 5 deletions

File tree

google/auth/transport/grpc.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@
1616

1717
from __future__ import absolute_import
1818

19-
import grpc
19+
try:
20+
import grpc
21+
except ImportError: # pragma: NO COVER
22+
raise ImportError(
23+
'gRPC is not installed, please install the grpcio package to use the '
24+
'gRPC transport.')
2025
import six
2126

2227

google/auth/transport/requests.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@
1818

1919
import logging
2020

21-
22-
import requests
21+
try:
22+
import requests
23+
except ImportError: # pragma: NO COVER
24+
raise ImportError(
25+
'The requests library is not installed, please install the requests '
26+
'package to use the requests transport.')
2327
import requests.exceptions
2428

2529
from google.auth import exceptions

google/auth/transport/urllib3.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@
3030
except ImportError: # pragma: NO COVER
3131
certifi = None
3232

33-
import urllib3
33+
try:
34+
import urllib3
35+
except ImportError: # pragma: NO COVER
36+
raise ImportError(
37+
'The urllib3 library is not installed, please install the urllib3 '
38+
'package to use the urllib3 transport.')
3439
import urllib3.exceptions
3540

3641
from google.auth import exceptions

google/oauth2/oauthlib.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@
2727

2828
import json
2929

30-
import requests_oauthlib
30+
try:
31+
import requests_oauthlib
32+
except ImportError: # pragma: NO COVER
33+
raise ImportError(
34+
'The requests-oauthlib library is not installed, please install the '
35+
'requests-oauthlib package to use google.oauth2.oauthlib.')
3136

3237
import google.oauth2.credentials
3338

0 commit comments

Comments
 (0)