Skip to content

Commit c4b652a

Browse files
Kn99HNShaneHarvey
authored andcommitted
PYTHON-2605: Improve mongodb+srv:// error message when dnspython is not installed (#602)
(cherry picked from commit 5388fde)
1 parent 57c92c1 commit c4b652a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

pymongo/uri_parser.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"""Tools to parse and validate a MongoDB URI."""
1717
import re
1818
import warnings
19+
import sys
1920

2021
from bson.py3compat import string_type, PY3
2122

@@ -425,8 +426,12 @@ def parse_uri(uri, default_port=DEFAULT_PORT, validate=True, warn=False,
425426
scheme_free = uri[SCHEME_LEN:]
426427
elif uri.startswith(SRV_SCHEME):
427428
if not _HAVE_DNSPYTHON:
428-
raise ConfigurationError('The "dnspython" module must be '
429-
'installed to use mongodb+srv:// URIs')
429+
python_path = sys.executable or "python"
430+
raise ConfigurationError(
431+
'The "dnspython" module must be '
432+
'installed to use mongodb+srv:// URIs. '
433+
'To fix this error install pymongo with the srv extra:\n '
434+
'%s -m pip install "pymongo[srv]"' % (python_path))
430435
is_srv = True
431436
scheme_free = uri[SRV_SCHEME_LEN:]
432437
else:

0 commit comments

Comments
 (0)