简体   繁体   中英

Elastic Beanstalk Django app deployment 502 Bad Gateway Server not running (No module named: 'application')

I deployed an application to AWS via Elastic Beanstalk, and when I finished pushing the project to aws (Elastic Beanstalk), I am faced with perpetual 502 Bad Gateway errors (probably because the Django app server never actually started, and Nginx can't proxy us through). Looking at the logs, I found a weird error that seems very specific, and erroneous. It looks like so:

 Traceback (most recent call last):
Dec 13 09:00:10 ip-172-31-35-65 web: File "/.../python3.8/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
Dec 13 09:00:10 ip-172-31-35-65 web: worker.init_process()
Dec 13 09:00:10 ip-172-31-35-65 web: File "/.../python3.8/site-packages/gunicorn/workers/gthread.py", line 92, in init_process
Dec 13 09:00:10 ip-172-31-35-65 web: super().init_process()
Dec 13 09:00:10 ip-172-31-35-65 web: File "/.../python3.8/site-packages/gunicorn/workers/base.py", line 134, in init_process
Dec 13 09:00:10 ip-172-31-35-65 web: self.load_wsgi()
Dec 13 09:00:10 ip-172-31-35-65 web: File "/.../python3.8/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
Dec 13 09:00:10 ip-172-31-35-65 web: self.wsgi = self.app.wsgi()
Dec 13 09:00:10 ip-172-31-35-65 web: File "/.../python3.8/site-packages/gunicorn/app/base.py", line 67, in wsgi
Dec 13 09:00:10 ip-172-31-35-65 web: self.callable = self.load()
Dec 13 09:00:10 ip-172-31-35-65 web: File "/.../python3.8/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
Dec 13 09:00:10 ip-172-31-35-65 web: return self.load_wsgiapp()
Dec 13 09:00:10 ip-172-31-35-65 web: File "/.../python3.8/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
Dec 13 09:00:10 ip-172-31-35-65 web: return util.import_app(self.app_uri)
Dec 13 09:00:10 ip-172-31-35-65 web: File "/.../python3.8/site-packages/gunicorn/util.py", line 359, in import_app
Dec 13 09:00:10 ip-172-31-35-65 web: mod = importlib.import_module(module)
Dec 13 09:00:10 ip-172-31-35-65 web: File "/.../python3.8/importlib/__init__.py", line 127, in import_module
Dec 13 09:00:10 ip-172-31-35-65 web: return _bootstrap._gcd_import(name[level:], package, level)
Dec 13 09:00:10 ip-172-31-35-65 web: File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
Dec 13 09:00:10 ip-172-31-35-65 web: File "<frozen importlib._bootstrap>", line 991, in _find_and_load
Dec 13 09:00:10 ip-172-31-35-65 web: File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
Dec 13 09:00:10 ip-172-31-35-65 web: ModuleNotFoundError: No module named 'application'
Dec 13 09:00:10 ip-172-31-35-65 web: [2021-12-13 09:00:10 +0000] [8602] [INFO] Worker exiting (pid: 8602)
Dec 13 09:00:10 ip-172-31-35-65 web: [2021-12-13 09:00:10 +0000] [8596] [INFO] Shutting down: Master
Dec 13 09:00:10 ip-172-31-35-65 web: [2021-12-13 09:00:10 +0000] [8596] [INFO] Reason: Worker failed to boot

Previously this application was working properly before this push (and it works perfectly fine in a virtual environment localhost). However now it seems to give this weird No module named 'application' error. I've run 'pip3 freeze > requirements.txt', I've tried to reboot the instance and deploy again (to no avail). If it helps the project is using django-crontab (the only reason I mention this is because I recently added it, and now this weird problem is arising). Also if I go back to previous version the app works again.... the wsgi file is unchanged, and the config file only had 4 lines injected (2 commands). So I'm very confused where this error is coming from.

If someone has faced this problem in the past, would you mind letting me know some things you tried to get it working again. Thanks
In the mean time I will be searching through the configuration files, requirements etc, to figure out what has went wrong.
Note this question is similar to this , however my problem seems to be more isolated, and more detailed.

The problem I faced was actually was due to a bad PostgreSQL connection . The connection settings were for development and invalid in production. The production connection wasn't working so it was throwing this "erroneous" error.
If you are getting this error it is likely you have configured production settings wrong (or are still using development settings). In my case it was a PostgreSQL problem, in yours it could be some other database or other connecting service.
check your configurations.

Bonus points to @Marcin for helping me search for a solution in my case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM