我用Flask创建了一个Web应用程序,它expose 了8080端口并显示了一些html页面,并将其部署到Google Cloud Run中. 这是基本代码.

app = Flask(__name__)

@app.before_request
def before_request():
    session.permanent = True
    app.permanent_session_lifetime = timedelta(minutes=settings.session_lifetime_minutes)
    session.modified = True
    g.user = current_user

login_manager = LoginManager()
login_manager.init_app(app)


@app.route("/")
def index():
    return render_template('authentication.html')

然而,当我设置了每个人都可以使用的服务入口,并通过浏览器访问由Google(https://myproject.run.app)提供的URL时,我等待了5/10秒,然后得到"服务不可用". 通过判断日志(log),我看到以下错误日志(log):

severity: "ERROR"
textPayload: "The request failed because either the HTTP response was malformed or connection to the instance had an error. Additional troubleshooting documentation can be found at: https://cloud.google.com/run/docs/troubleshooting#malformed-response-or-connection-error"

然而,在故障排除指南中,我没有发现任何有用的信息.

当我设置只有内部用户才能使用的服务入口,并try 使用Google建议的cURL时,我得到的结果如下:

<html><head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>404 Page not found</title>
</head>
<body text=#000000 bgcolor=#ffffff>
<h1>Error: Page not found</h1>
<h2>The requested URL was not found on this server.</h2>
<h2></h2>
</body></html>

有人能帮我了解一下发生了什么事吗?谢谢!

推荐答案

在您的 comments 中:

if name == "main":
    app.run(ssl_context="adhoc", host="0.0.0.0", port=8080)

这是你的问题ssl_context="adhoc".监听程序必须使用HTTP而不是HTTPS.

if name == "main":
    app.run(host="0.0.0.0", port=8080)

建议:从环境中读取端口值,而不是硬编码.

app.run(host="0.0.0.0", port=int(os.environ.get("PORT", 8080)))

Python相关问答推荐

为什么我的Python代码在if-else声明中的行之前执行if-else声明中的行?

无法通过python-jira访问jira工作日志(log)中的 comments

如何使用pytest来查看Python中是否存在class attribution属性?

将9个3x3矩阵按特定顺序排列成9x9矩阵

如果满足某些条件,则用另一个数据帧列中的值填充空数据帧或数组

在单个对象中解析多个Python数据帧

Tkinter菜单自发添加额外项目

旋转多边形而不改变内部空间关系

如果初始groupby找不到满足掩码条件的第一行,我如何更改groupby列,以找到它?

如何在Pyplot表中舍入值

基于行条件计算(pandas)

搜索按钮不工作,Python tkinter

在Python中控制列表中的数据步长

在极点中读取、扫描和接收有什么不同?

SpaCy:Regex模式在基于规则的匹配器中不起作用

根据过滤后的牛郎星图表中的数据计算新系列

在Pandas 中以十六进制显示/打印列?

Groupby并在组内比较单独行上的两个时间戳

如何在Python中画一个只能在对角线内裁剪的圆?

如何计算Pandas 中具有特定条件的行之间的天差