Forums

Not able to connect pymongo Mongodb [srv]

I have a paid account, and getting errors below to connect to mongodb using pymongo. I have already installed dnspython as per suggestion to connect with +srv

Traceback (most recent call last): File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 2077, in wsgi_app response = self.full_dispatch_request() File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1525, in full_dispatch_request rv = self.handle_user_exception(e) File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1523, in full_dispatch_request rv = self.dispatch_request() File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1509, in dispatch_request return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args) File "/home/zenavu/mysite/flask_app.py", line 121, in get_cposts return apis.apis.get_all_posts() File "/home/zenavu/mysite/apis/apis.py", line 24, in get_all_posts cluster = MongoClient("mongodb+srv://xx:xx@cluster0.vhmwp.mongodb.net/?retryWrites=true&w=majority",tlsAllowInvalidCertificates=True,connectTimeoutMS=30000, socketTimeoutMS=None, connect=False, maxPoolsize=1) File "/usr/local/lib/python3.8/dist-packages/pymongo/mongo_client.py", line 704, in init res = uri_parser.parse_uri( File "/usr/local/lib/python3.8/dist-packages/pymongo/uri_parser.py", line 469, in parse_uri raise ConfigurationError( pymongo.errors.ConfigurationError: 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]"

Is it installed for the python version (3.8) that you are running your code with? Install it with pip3.8 with --user flag