gpt4 book ai didi

python-3.x - 已满足要求时 ConfigError "dnspython must be installed"

转载 作者:行者123 更新时间:2023-12-03 23:12:30 30 4
gpt4 key购买 nike

尝试将 Colab Notebook 连接到 Atlas 上的 MongoDB。

from pymongo import MongoClient
uri = "mongodb+srv://MYUSERNAME:mypassword@mydatabase.mongodb.net/test"

client = MongoClient(uri)

我收到一个配置错误:
"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

最佳答案

您必须重新启动运行时才能使更改生效:

  • !pip install dnspython
  • 重新启动运行时 Runtime -> Restart runtime...
  • 运行您的代码
  • 关于python-3.x - 已满足要求时 ConfigError "dnspython must be installed",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57280947/

    30 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com