pymongo - "dnspython" module must be installed to use mongodb+srv:// URIs

PythonMongodbPymongo

Python Problem Overview


I am trying to connect MongoDB from Atlas.

My mongo uri is: mongodb+srv://abc:[email protected]/admin?retryWrites=True

My pymongo version is 3.6.1

I have installed dnspython and done import dns

But i still get this error:

> dnspython module must be installed to use mongodb+srv:// URI

Python Solutions


Solution 1 - Python

In order to use mongo+srv protocol, you need to install pymongo-srv Launch this command to do it with python 3:

pip3 install pymongo[srv]

or this one for other versions:

pip install pymongo[srv]

And as suggested by @lukrebs, add quotes for ZSH:

pip3 install 'pymongo[srv]'

Solution 2 - Python

I solved this problem with:

$ python -m pip install pymongo[srv]

Solution 3 - Python

I would like to answer my own questions here. As I mentioned in the comment, the kernel of the jupyter notebook has to be restarted in order for the pymongo to take effect of the loaded dnspython.

Solution 4 - Python

In requirements.txt, replace pymongo with pymongo[tls,srv], as mentioned https://github.com/getredash/redash/issues/2603">here</a>;.

Solution 5 - Python

I got stuck with the same problem and tried

pip install dnspython==2.0.0

This is the latest version from https://pypi.org/project/dnspython/

It worked :D

Solution 6 - Python

you can use mongo:// instead of mongodb+srv://

Solution 7 - Python

May be the protocol, your URI should start with:

mongo+srv instead of mongo+src

If it still not working please put a pip list with the versions of PyMongo and dnspython (and version of python that you are using)

Solution 8 - Python

I had the same problem on Ubuntu 18 but since I am using Anaconda I just tried

Conda install dns python

I had an IPython running, it did not work while the same instance was open but when I restarted that instance it worked.

On a different machine using

Conda install dns python

and it worked but I had to restart my machine altogether due to a different reason before testing it

Solution 9 - Python

pip install dnspython

dnspython is a DNS toolkit for Python. It supports almost all record types. It can be used for queries, zone transfers, and dynamic updates. It supports TSIG authenticated messages and EDNS0.

Solution 10 - Python

I had the same issue and found the following line.

import dns.resolver
dns.resolver.default_resolver=dns.resolver.Resolver(configure=False)
dns.resolver.default_resolver.nameservers=['8.8.8.8'] 

It worked for me.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionaddictedView Question on Stackoverflow
Solution 1 - PythonvebenView Answer on Stackoverflow
Solution 2 - PythonJonathan CardosoView Answer on Stackoverflow
Solution 3 - PythonaddictedView Answer on Stackoverflow
Solution 4 - Pythonalter123View Answer on Stackoverflow
Solution 5 - PythonNoobajaxpythonView Answer on Stackoverflow
Solution 6 - PythonmsklcView Answer on Stackoverflow
Solution 7 - PythonFernando BynView Answer on Stackoverflow
Solution 8 - PythonMaxView Answer on Stackoverflow
Solution 9 - PythonMD SHAYONView Answer on Stackoverflow
Solution 10 - PythonOshidiView Answer on Stackoverflow