GAE: How to include other classes in my app engine main.py

186 Views Asked by At

I want to use my python file, which consists of some classes in my app engine. This file is present in the root directory. When I import that file into main.py, my application is not starting - I'm getting an error:

"Error: Server Error The server encountered a temporary error and could not complete your request. Please try again in 30 seconds."

Should I set any environment variables?
How I can import and call other functions which I already have written.

app.yaml

runtime: python
env: flex

runtime_config:
        python_version: 3

entrypoint: gunicorn -b:$PORT --workers 2 main:app
manual_scaling:
        instances: 1
resources:
        cpu: 1
        memory_gb: 0.5
        disk_size_gb: 10

main.py

from flask import Flask
import sample
app = Flask(__name__)
@app.route('/')
def hello():
    return 'Hello Everyone!'

@app.route('/sample')
def foo():
    return sample.Sample()

sample.py

def Sample():
    return "hello world"

requirements.txt

Flask==1.1.1
gunicorn==19.3.0
2

There are 2 best solutions below

0
Vikram Shinde On

I tested this files on my local, it worked fine and also deployed on Google Cloud, it is working fine there too. Since it is flex environment which takes time to boot as compared to GAE standard environment ref doc Give sometime and try again.

2
Deniss T. On

I see no errors within your code. Moreover, I have tested it and could deploy the app successfully.

The issue you are experiencing will require more project-specific details. Please contact the Google Cloud Platform support for a deeper investigation.