diff --git a/pymongo/uri_parser.py b/pymongo/uri_parser.py index a683b2fa6d..60d03ba497 100644 --- a/pymongo/uri_parser.py +++ b/pymongo/uri_parser.py @@ -16,6 +16,7 @@ """Tools to parse and validate a MongoDB URI.""" import re import warnings +import sys from urllib.parse import unquote_plus @@ -416,8 +417,12 @@ def parse_uri(uri, default_port=DEFAULT_PORT, validate=True, warn=False, scheme_free = uri[SCHEME_LEN:] elif uri.startswith(SRV_SCHEME): if not _HAVE_DNSPYTHON: - raise ConfigurationError('The "dnspython" module must be ' - 'installed to use mongodb+srv:// URIs') + python_path = sys.executable or "python" + raise ConfigurationError( + 'The "dnspython" module must be ' + 'installed to use mongodb+srv:// URIs. ' + 'To fix this error install pymongo with the srv extra:\n ' + '%s -m pip install "pymongo[srv]"' % (python_path)) is_srv = True scheme_free = uri[SRV_SCHEME_LEN:] else: