Dnspython module must be installed

When adding the uri mongodb+srv://<username>:<password>@mongodb-courses-1n3ap.azure.mongodb.net/test?retryWrites=true&w=majority string and running the jupyter notebook code:

# import the pymongo library - this is the Python driver!
import pymongo

# replace "uri" with your Atlas URI string - should look like mongodb+srv://...
uri = "mongodb+srv://<username>:<password>@mongodb-courses-1n3ap.azure.mongodb.net/test?retryWrites=true&w=majority"
client = pymongo.MongoClient(uri)
mflix = client.sample_mflix

# movies is our collection handle - it refers to the sample_mflix.movies collection
movies = mflix.movies

This error is raised: ConfigurationError: The "dnspython" module must be installed to use mongodb+srv:// URIs

I’ve attempted to update pymongo, pymongo[tls,srv] specifically, and dnspython and have tried rebooting jupyter notebook / kernel. Any suggestions are greatly appreciated.

Try running the below command on your terminal:

python -m pip install pymongo[srv]

If you are on Linux and have multiple versions of python, run:
python3 -m pip install pymongo[srv]

For pymongo to connect to a MongoDB Server using SSL, PyMongo-srv module must be present in your python environment and this comes pre-installed when you install using the command:
pip install pymongo

But there are few cases where this module might not get installed. In such cases we have to install it manually using the commands mentioned above

Thank you for your response! Ive already attempted that solution, though.

I’ve attempted to update pymongo, pymongo[tls,srv] specifically, and dnspython and have tried rebooting jupyter notebook / kernel. Any suggestions are greatly appreciated.

I mentioned before that I attempted to update pymongo[tls,srv] but I also tried installing/updating them separately as well.

Have you tried uninstalling and reinstalling pymongo package?

Command to uninstall:
pip uninstall pymongo

Command to install
pip install pymongo

Oh good idea! I have not. I’ll try that next chance I get. Thanks!

1 Like

@Harshavardhan_50878, thanks for the suggestion! I had to uninstall and reinstall pymongo twice, including a separate pymongo[srv] and then had to update the dnspython library. It’s working now, though :slight_smile:

2 Likes