正在尝试将Colab笔记本连接到阿特拉斯上的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发布于 2020-02-19 15:29:41
您必须重新启动运行时才能使更改生效:
!pip install dnspythonRuntime -> Restart runtime...发布于 2020-04-15 14:49:35
尝试安装pymongosrv和tls !pip3 install pymongo[srv] !pip3 install pymongo[tls]
https://stackoverflow.com/questions/57280947
复制相似问题