尝试将Colab Notebook连接到Atlas上的MongoDB。
from pymongo import MongoClient
uri = "mongodb+srv://MYUSERNAME:mypassword@mydatabase.mongodb.net/test"
client = MongoClient(uri)
我收到CongfigurationError:
"dnspython" module must be installed to use mongodb+srv:// URIs.
我安装了模块。
pip install dnspython
将邮件退回
Requirement already satisfied: dnspython in /usr/local/lib/python3.6/dist-packages (1.16.0)
不知道怎么了。
几天前这与另一个colab笔记本(和另一个数据库)一起使用。
这是整个错误消息:
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
答案 0 :(得分:9)
您必须重新启动运行系统才能使更改生效:
!pip install dnspython
Runtime -> Restart runtime...
答案 1 :(得分:1)
尝试安装pymongo [srv]和[tls]
!pip3 install pymongo[srv]
!pip3 install pymongo[tls]