首页 > 解决方案 > Pymongo 通过 atlas 连接到 mongodb 时出错

问题描述

我正在尝试通过 atlas 和 pymongo 建立与我的 mongodb 数据库的连接。我正在使用从 atlas 页面提供的连接字符串连接我的应用程序,并且一切似乎都工作正常。我可以连接到我的数据库,但是当我尝试计算我的数据库中有多少条目/检索/将数据发送到 atlas 时,我收到一条错误消息。

import pymongo
import dns

client = pymongo.MongoClient("mongodb+srv://username:<password>@storedinputs-vc4cl.mongodb.net/test?retryWrites=true")
db = client.get_database("dbname")
records = db.collectiontable

count = records.count_documents({})
print(count)

然后我收到以下错误:

[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issue
r certificate (_ssl.c:1056),storedinputs-shard-00-00-vc4cl.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] cer
tificate verify failed: unable to get local issuer certificate (_ssl.c:1056)

我再次逐行尝试,一切正常,直到我尝试计算我的集合中的文档数量。我很感激我能得到的所有帮助。

标签: pythonmongodbsslpymongomongodb-atlas

解决方案


尝试

client = pymongo.MongoClient("mongodb+srv://username:<password>@storedinputs-vc4cl.mongodb.net/test", ssl=True,ssl_cert_reqs='CERT_NONE')

它应该工作。


推荐阅读