Mongodb python 中的 ssl 证书错误,我该如何修复该错误?

Mongodb ssl certificate error in python, how can i fix the error?

当我尝试对我的共享 mongodb 执行操作时,我在 python 中开发时遇到此错误,我该如何解决?

<ServerDescription ('cluster0xxxxmongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('cluster0xxxxmongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1129)')>

首先安装证书

pip install certifi

然后在代码中使用:

import certifi
client = pymongo.MongoClient(f"mongodb+srv://username:password@cluster0.xxxxx.mongodb.net/db?retryWrites=true&w=majority",tlsCAFile=certifi.where())