Forums

Error connecting to mongodb atlas srv using pymongo

I have a paid hacker account and trying to use pymongo in my django web application. I have aready installed pymongo[srv] using pip install pymongo[srv]. I am using virtualenv so didn't use --user tag. Still I am unable to connect to Mongo db and getting below error

The "dnspython" module must be installed to use mongodb+srv:// URIs. To fix this error install pymongo with the srv extra: /usr/local/bin/uwsgi -m pip install "pymongo[srv]"

I have gone through the mongodb blog pages https://blog.pythonanywhere.com/178/ and https://help.pythonanywhere.com/pages/MongoDB/ . In Mongodb atlas, I have already allowed 0.0.0.0/0 , so hope its not a network issue.

Not sure what I am missing, please advice.

Are you sure that your code is running in the environment that you installed package for?

yes. I guess so. I have installed it in the virtual envirnonment. workon <virtualenv> (<virtualenv>) 09:17 ~ $ pip install pymongo[srv] when I try the above now, I got requirement already satisfied. The page without pymongo connection is loading fine. so its the same environment in which it is installed. Below are the packages installed in the virutalenv

09:56 ~ $ workon <virtualenv> (<virtualenv>) 09:57 ~ $ pip freeze asgiref==3.7.2 Django==4.2.2 dnspython==2.3.0 mongo-datatables==0.3.0 Pillow==9.5.0 pymongo==4.3.3 sqlparse==0.4.4 typing_extensions==4.6.3 (<virtualenv>) 09:57 ~ $

(<virtualenv>) 09:57 ~ $ python --version Python 3.10.5

Take look at your "Web" page and see if the web app is configured to use it in "Virtualenv" section.

so helpful. That setting really worked. Thanks a lot fjl !!

Glad it worked for you!