谷歌云平台 gunicorn:未找到

时间:2021-03-31 17:03:18

标签: python google-cloud-platform gunicorn

我正在尝试在 google 云平台上运行 python 代码,但遇到此错误消息

错误:(gcloud.app.deploy) 错误响应:[9] 应用程序启动错误!代码:APP_CONTAINER_CRASHED /bin/sh: 1: exec: gunicorn: 未找到

这是我的python代码:

import base64
import requests
from flask import Flask, jsonify, request
import json

# declared an empty variable for reassignment
response = []
count = 0

# creating the instance of our flask application
main2 = Flask(__name__)

# route to entertain our post and get request from flutter app
@main2.route('/name', methods=['GET', 'POST'])
def nameRoute():

    # fetching the global response variable to manipulate inside the function
    global response
    global count

    # checking the request type we get from the app
    if(request.method == 'POST'):
        file = request.files['name']
        images = [base64.b64encode(file.read()).decode("ascii")]
        your_api_key = "y9wOjqSB8ORZ2O4bPfyk3oYlgl8PIo8PpLaMOoadhwMrhGQtkP"
        json_data = {
            "images": images,
            "modifiers": ["similar_images"],
            "plant_details": ["common_names", "url", "wiki_description", "taxonomy"]
        }
        res = requests.post(
            "https://api.plant.id/v2/identify",
            json=json_data,
            headers={
                "Content-Type": "application/json",
                "Api-Key": your_api_key
            }).json()
        for suggestion in res["suggestions"]:
            response.append(suggestion["plant_name"])
            count = count + 1
        return " "  # to avoid a type error

    else:
        try1 = len(response)
        try2 = try1 - count
        count = 0
        # sending data back to your frontend app
        return jsonify({'name': response[try2]})

if __name__ == "__main__":
    main2.run(port="8000", host='0.0.0.0', debug=True)

这是我的 app.yaml:

runtime: python
env: flex
entrypoint: gunicorn -b :$PORT main2:app

runtime_config:
  python_version: 3

# This sample incurs costs to run on the App Engine flexible environment. 
# The settings below are to reduce costs during testing and are not appropriate
# for production use. For more information, see:
# https://cloud.google.com/appengine/docs/flexible/python/configuring-your-app-with-app-yaml
manual_scaling:
  instances: 1
resources:
  cpu: 1
  memory_gb: 2
  disk_size_gb: 10

1 个答案:

答案 0 :(得分:1)

确保将 gunicorn 添加到您的 requirements.txt 文件中。

查看此 link 以获取更多信息并全面了解 App Engine 柔性版上的应用程序启动方式。