python - 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)
我再次逐行尝试,一切正常,直到我尝试计算我的集合中的文档数量。我很感激我能得到的所有帮助。
解决方案
尝试
client = pymongo.MongoClient("mongodb+srv://username:<password>@storedinputs-vc4cl.mongodb.net/test", ssl=True,ssl_cert_reqs='CERT_NONE')
它应该工作。
推荐阅读
- python - 如何使用 pip METADATA Requires-Dist 中的“额外”标志?
- validation - 默认验证消息 ASP.NET Core
- r - Bookdown 到 PDF 定理环境副本
- cytoscape.js - 我们可以为循环边缘类型或子父边缘选择另一种边缘形式吗?
- python - 如何将两个numpy数组合二为一?
- node.js - 包含 ProxyPass 和 ProxyPassReverse(AWS Lightsail 上的 Bitnami Node.js 服务器)的正确位置
- json - 读取真实数据库以快速重置密码
- javascript - .on('change') 有可靠的替代方案吗?
- python - 保护联系表单 API
- c++ - 如何定期同步线程?