简体   繁体   English

Flask 和 MongoEngine 出现“SSL:CERTIFICATE_VERIFY_FAILED”错误

[英]“SSL: CERTIFICATE_VERIFY_FAILED” error with Flask and MongoEngine

I am trying to send a GET request to my Mongo server, and this is the current issue I am having.我正在尝试向我的 Mongo 服务器发送 GET 请求,这是我当前遇到的问题。

[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1122)')>]>

I am unable to figure out what is happening.我无法弄清楚发生了什么。 My code looks about correct so I am a bit confused.我的代码看起来是正确的,所以我有点困惑。

Here is my app/main file:这是我的应用程序/主文件:

from flask import Flask

from flask_mongoengine import MongoEngine

db = MongoEngine()

# Did pip install certifi for security certifications

def create_app(config=None):
    app = Flask(__name__)
if config is not None:
    app.config.from_object(config)

db.init_app(app)

@app.route("/")
def hello():
    return "Hello World"

from user.views import user_page
# This means that we will use /user/login....
# To access the login page
app.register_blueprint(user_page, url_prefix="/user")

return app

Here is my config file:这是我的配置文件:

# MONGODB_DB = 'my-db'
MONGODB_SETTINGS = {
    'host': 'mongodb+srv://jack123:coolPass@my-db.ap6mq.mongodb.net/my-db?retryWrites=true&w=majority'
}

I'd certainly appreciate any sort of help on this.我当然会很感激这方面的任何帮助。 This is something I have been stuck on for a while now.这是我一直坚持一段时间的事情。 I don't know where to get the certificate or how to turn it off.我不知道从哪里获得证书或如何将其关闭。

I doubt certifi is going to do anything automatically for MongoDB connections.我怀疑 certifi 会自动为 MongoDB 连接做任何事情。

If your system doesn't come with the certificates needed for Atlas, most likely you will need to:如果您的系统没有提供 Atlas 所需的证书,您很可能需要:

  • Figure out/hunt down the CA certificate that Atlas uses (consult Atlas documentation, if this doesn't help you can extract the CA certificate from the connection using openssl command-line tool)找出/查找 Atlas 使用的 CA 证书(请参阅 Atlas 文档,如果这对您没有帮助,您可以使用openssl命令行工具从连接中提取 CA 证书)
  • Provide this certificate to pymongo using a URI option (consult pymongo documentation for how to do this)使用 URI 选项将此证书提供给 pymongo(有关如何执行此操作,请参阅 pymongo 文档)

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

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