You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

部署Flask_PyMongo至GCP App Engine时SSL握手失败求助

部署Flask-PyMongo至Google Cloud App Engine时SSL握手失败问题

我是Eitan,刚接触Google Cloud与Flask-PyMongo。将应用部署至App Engine时,尽管已在MONGO_URI中指定本地pem文件至tlsCAFile属性,仍出现错误:pymongo.errors.ServerSelectionTimeoutError: SSL handshake failed。我尝试过certifi.where()、ssl=False、ssl_cert_reqs=CERT_NONE及将pem证书放入本地项目等方法,问题仍未解决。

以下是我的代码:

app.py

from flask import Flask, render_template
from flask_pymongo import PyMongo, MongoClient
app = Flask(__name__)
# 注:密码没问题,只是不想泄露真实密码
app.config["MONGO_URI"] = "mongodb+srv://eitanbrochstein:password@cluster0.rhtkmvj.mongodb.net/Flask?authSource=admin&tlsCAFile=cacert.pem"
mongo = PyMongo(app)

@app.route("/")
def home():
    # #创建一条数据
    print(mongo.db.users.insert_one({"user": "Username"}))
    return render_template("index.html")

if __name__ == "__main__":
    app.run(debug=True)

app.yaml

runtime: python
env: flex
entrypoint: gunicorn -b :8080 app:app

runtime_config:
    operating_system: "ubuntu22"
    runtime_version: "3.11"

requirements.txt

Flask==2.1.3
Flask-PyMongo
certifi
dnspython
Werkzeug==2.2.2
gunicorn

内容的提问来源于stack exchange,提问作者Eitan Travels

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 05:35:05