简体   繁体   English

通过地图集连接到 mongodb 的 Pymongo 错误

[英]Pymongo error connecting to mongodb via atlas

I am trying to establish a connection to my mongodb database via atlas and pymongo.我正在尝试通过 atlas 和 pymongo 建立到我的 mongodb 数据库的连接。 I am connecting my application using the connection string given from atlas page, and everything seems to be working fine.我正在使用 atlas 页面提供的连接字符串连接我的应用程序,一切似乎都运行良好。 I can connect to my database but then I get an error message when I try to count how many entries are in my database/retrieve/send data to 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)

Then I get the following error:然后我收到以下错误:

[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)

Again I've tried it line by line and everything works fine until I try and count the amount of documents in my collection.我再次逐行尝试,一切正常,直到我尝试计算我的收藏中的文档数量。 I appreciate all the help I can get.我很感激我能得到的所有帮助。

Try with试试

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

It should work.它应该工作。

查看 PyMongo 文档中的故障排除部分,它涵盖了您遇到的问题以及可能的解决方案。

只需将 ' &ssl=true&ssl_cert_reqs=CERT_NONE ' 添加到数据库字符串中,它就可以正常工作!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM