使用 PyMongo 的 MongoDB Atlas 出现 ServerTimeoutError(运行设置代码)

Som*_*wal 3 python mongodb mongodb-atlas

我正在运行 MongoDB 的起始代码,尝试连接到我刚刚在 MongoDB Atlas 中设置的集群。我收到服务器选择超时错误。

我在 MongoDB 故障排除文档中找不到有关此问题的任何内容。

client = pymongo.MongoClient(
    "mongodb+srv://USR:PWD@cluster0-eoik8.mongodb.net/test?retryWrites=true&w=majority")
db = client.admin
pprint(db.command("serverStatus"))
Run Code Online (Sandbox Code Playgroud)

我已经正确编码了 URL(使用在线 URL 编码服务)。

错误是

pymongo.errors.ServerSelectionTimeoutError: connection closed,connection closed,connection closed

Som*_*wal 5

它不起作用的原因是我没有将我的 IP 地址列入白名单。