Ghaida_att
Ghaida_att

Reputation: 11

google cloud platform gunicorn: not found

i am trying to run a python code on google cloud platform and i faced this error message

ERROR: (gcloud.app.deploy) Error Response: [9] Application startup error! Code: APP_CONTAINER_CRASHED /bin/sh: 1: exec: gunicorn: not found

this is my python code:

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)

and here is my 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

Upvotes: 1

Views: 803

Answers (1)

Daniel Ocando
Daniel Ocando

Reputation: 3774

Make sure to add gunicorn to your requirements.txt file.

Check this link for more information and a complete understanding on how the application startup works on App Engine Flexible.

Upvotes: 1

Related Questions