【问题标题】:Flask/python route runs locally but crashes on GCPFlask/python 路由在本地运行,但在 GCP 上崩溃
【发布时间】:2018-08-10 15:39:54
【问题描述】:

我想知道为什么以下 Flask/Python 路由在本地运行,但在 GCP(谷歌云平台)上出现内部服务器错误?

在包含路由“/test/”之前,我部署到 GCP 并且能够访问所有路由。

在包含路由“/test/”后,我能够访问除“/test/”路由之外的所有路由,这会引发内部服务器错误。

非常感谢任何建议。 谢谢。

@app.route('/test/')
def test():
    p = subprocess.Popen(["coverage", "run", "--branch", "test.py"],
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            stdin=subprocess.PIPE)
    out, err = p.communicate()
    output=err+out
    output = output.decode("utf-8")

    return render_template('test.html', output = "<br/>".join(output.split("\n")))

test.html

<html>
    <head> </head>
    <body>
        <pre><code>{{ output }}</code></pre>
    </body>
</html>

【问题讨论】:

  • 错误和回溯是什么?
  • 另外,“部署到 GCP”到底是什么意思?这可能意味着几个不同的事情。但无论如何,您可能有 75% 的机会没有在它运行的任何 GCP 环境中安装 coverage
  • 谢谢你,Mark,正如你所指出的,我忘了在我的 requirements.txt 文件中包含 coverage。加入后,问题解决了!

标签: python flask google-cloud-platform subprocess


【解决方案1】:

coverage 需要包含在 requirements.txt 文件中,以便可以安装在 GCP 环境中。

【讨论】:

    猜你喜欢
    • 2021-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-17
    • 1970-01-01
    • 1970-01-01
    • 2014-09-18
    • 2021-08-15
    相关资源
    最近更新 更多