我正在尝试连接到我的共享 MongoDB 集群,但不断收到以下错误: SSL 握手失败:ac-ascvkib-shard-00-02.hkzvmvh.mongodb.net:27017: [WinError 10054] 现有连接被远程主机强制关闭。
我使用的确切代码如下:
from pymongo.mongo_client import MongoClient
# I replaced <password> with my own password
uri = "mongodb+srv://admin:<password>@cluster0.hkzvmvh.mongodb.net/?retryWrites=true&w=majority"
# Create a new client and connect to the server
client = MongoClient(uri)
# Send a ping to confirm a successful connection
try:
client.admin.command('ping')
print("Pinged your deployment. You successfully connected to MongoDB!")
except Exception as e:
print(e)
我正在使用Python 3.11并且我正在使用pymongo==3.11。我在 Windows 机器上,似乎错误消息被打印了多次。
您需要在连接字符串中提供服务器 CA 证书
uri = "mongodb+srv://admin:<password>@cluster0.hkzvmvh.mongodb.net/?retryWrites=true&w=majority&tlsCAFile=isrgrootx1.pem"
下载文件
您是否尝试过替换为您的密码?