简体   繁体   中英

Pymongo error connecting to mongodb via atlas

I am trying to establish a connection to my mongodb database via atlas and pymongo. I am connecting my application using the connection string given from atlas page, and everything seems to be working fine. 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.

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 ' 添加到数据库字符串中,它就可以正常工作!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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