尝试使用Python客户端连接MongoDB时出现SSL握手失败错误

问题描述 投票:0回答:2

我正在尝试连接到我的共享 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 机器上,似乎错误消息被打印了多次。

python mongodb pymongo
2个回答
1
投票

您需要在连接字符串中提供服务器 CA 证书

uri = "mongodb+srv://admin:<password>@cluster0.hkzvmvh.mongodb.net/?retryWrites=true&w=majority&tlsCAFile=isrgrootx1.pem"

您可以从 https://letsencrypt.org/certificates/

下载文件

我认为是这个:https://letsencrypt.org/certs/isrgrootx1.pem


0
投票

您是否尝试过替换为您的密码?

© www.soinside.com 2019 - 2024. All rights reserved.