Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ConfigError "dnspython must be installed" when requirement already satisfied

Trying to connect a Colab Notebook to a MongoDB on Atlas.

from pymongo import MongoClient
uri = "mongodb+srv://MYUSERNAME:[email protected]/test"  

client = MongoClient(uri)

I am getting a CongfigurationError:

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

I installed the module.

pip install dnspython

Got the message back

Requirement already satisfied: dnspython in /usr/local/lib/python3.6/dist-packages (1.16.0)

Do not know what is wrong.

This worked a few days ago with another colab notebook (and another database).

Here is the entire error message:

ConfigurationError                        Traceback (most recent call last)
<ipython-input-30-a6c89e14e64f> in <module>()
----> 1 client = MongoClient(uri)

1 frames
/usr/local/lib/python3.6/dist-packages/pymongo/mongo_client.py in __init__(self, host, port, document_class, tz_aware, connect, type_registry, **kwargs)
    522         for entity in host:
    523             if "://" in entity:
--> 524                 res = uri_parser.parse_uri(entity, port, warn=True)
    525                 seeds.update(res["nodelist"])
    526                 username = res["username"] or username

/usr/local/lib/python3.6/dist-packages/pymongo/uri_parser.py in parse_uri(uri, default_port, validate, warn)
    316     elif uri.startswith(SRV_SCHEME):
    317         if not _HAVE_DNSPYTHON:
--> 318             raise ConfigurationError('The "dnspython" module must be '
    319                                      'installed to use mongodb+srv:// URIs')
    320         is_srv = True

ConfigurationError: The "dnspython" module must be installed to use mongodb+srv:// URIs
like image 947
BlonDev Avatar asked Jul 30 '19 22:07

BlonDev


1 Answers

You have to restart runtime to have the changes take effect:

  1. !pip install dnspython
  2. Restart runtime Runtime -> Restart runtime...
  3. Run your code
like image 170
Nate Raw Avatar answered Oct 02 '22 15:10

Nate Raw