Henry Woody
Henry Woody

Reputation: 15652

Python 3 Django on App Engine Standard: App Fails to Start

I'm trying to deploy a Django application on Google App Engine in the Standard Python37 Environment. I've had a version of it running fine in the Flexible environment, but I'm creating a staging version that I want to run in the Standard env.

When I deploy and visit the app I get a 500 error. Looking in the logs I can see some messages about exceptions in worker processes. I get the error:

ModuleNotFoundError: No module named 'main'

This is the stack trace from the error:

Traceback (most recent call last):

File "/env/lib/python3.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker worker.init_process()

File "/env/lib/python3.7/site-packages/gunicorn/workers/gthread.py", line 104, in init_process super(ThreadWorker, self).init_process()

File "/env/lib/python3.7/site-packages/gunicorn/workers/base.py", line 129, in init_process self.load_wsgi()

File "/env/lib/python3.7/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi self.wsgi = self.app.wsgi()

File "/env/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi self.callable = self.load()

File "/env/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load return self.load_wsgiapp()

File "/env/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp return util.import_app(self.app_uri)

File "/env/lib/python3.7/site-packages/gunicorn/util.py", line 350, in import_app import(module)

ModuleNotFoundError: No module named 'main'

I haven't modified my_site/wsgi.py since Django created it for me, here it is:

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "my_site.settings")

application = get_wsgi_application()

This is my app.yaml:

runtime: python37
env: standard

beta_settings:
    cloud_sql_instances: project:us-west1:sql-instance

handlers:
- url: /static
  static_dir: staticfiles/
- url: .*
  secure: always
  redirect_http_response_code: 301
  script: my_site.wsgi.application

env_variables:
  # vars

This matches pretty close with the app.yaml in: https://cloud.google.com/python/django/appengine. I've also tried changing script to auto as shown here: https://cloud.google.com/appengine/docs/standard/python3/config/appref, but still get the same error.

I've looked at this question: Django - gunicorn on App Engine. Error: 'No Module Named my_project', and my_site does have an underscore in it, but isn't camelCased.

I'm not sure what the source of this error is. Any ideas would be much appreciated.

Upvotes: 6

Views: 5001

Answers (2)

Piotr
Piotr

Reputation: 41

You can also deploy it without entrypoint but your app object needs to be located in main.py file in root directory.

Check example description of such deployment here

Upvotes: 0

cwlau
cwlau

Reputation: 428

You may need to add entrypoint to your app.yaml

runtime: python37
entrypoint: gunicorn -b :8080 my_site.wsgi

...(remaining parts of your app.yaml)

Reference: https://cloud.google.com/appengine/docs/standard/python3/runtime

Upvotes: 9

Related Questions