AWS WSGIPath refers to a file that does not exist - python

I have been going through every thread on here and have tried all the ways I can think of. I am following the AWS deploy django tutorial and keep getting this error
ERROR Your WSGIPath refers to a file that does not exist.
I have used eb config to edit the file to the same path thats in django.config which is endjango/wsgi but nothing I have tried has worked. Also tried wrapping it in quotes and that did not work either.
Heres my file
django.config
option_settings:
"aws:elasticbeanstalk:container:python":
WSGIPath: ebdjango/wsgi.py
Config.yml
branch-defaults:
default:
environment: django-env
group_suffix: null
global:
application_name: django-tutorial
branch: null
default_ec2_keyname: aws-eb
default_platform: python-3.6
default_region: us-east-1
include_git_submodules: true
instance_profile: null
platform_name: null
platform_version: null
profile: eb-cli
repository: null
sc: null
workspace_type: Application

Figured out the issue ebextensions and requirements.txt need to be in root folder. Next run eb config and edit wsgi path to match endjango/wsgi.py.

You can also configure your wsgi path from UI. Go to configure tab and edit it there. Another option is using terminal.

Related

Gunicorn Config File I've Created Doesn't Exist

I am using Django and Gunicorn to create a blog and am wanting to run my config file that I have created.
This is the path to my config file (the conf folder is at the same level as manage.py):
/var/www/website.co.uk/blog/DjangoBlog/Articles/conf/gunicorn_config.py
I am in this path: /var/www/website.co.uk/blog/DjangoBlog/Articles and run this command:
gunicorn -c gunicorn_config.py Articles.wsgi
However, it returns the error:
Error: 'gunicorn_config.py' doesn't exist
Is Gunicorn looking in the wrong place for my config file?
Any help would be massively appreciated. I have not been able to solve this for a while.
Kind regards
you dont seem to be using the correct directory for the gunicorn config file, try this
gunicorn -c ./conf/gunicorn_config.py Articles.wsgi

Elastic Beanstalk Static Folder 403 Error

I'm stuck trying to solve a "403 Forbidden" error in my Elastic Beanstalk Flask application. I have set up my python.config file as below:
option_settings:
aws:elasticbeanstalk:container:python:staticfiles:
"/static/": "/static/"
"/templates/": "/templates/"
commands:
01_set_file_permissions:
command: "chmod 777 /opt/python/current/app/static/"
The static folder was initially giving a 404 but the static files section of python.config fixed that. My problem is I can't get the file permissions to be recognised on the server. It always returns a 403 error. Please help.
I worked out the fix. The option_settings section was incorrect in that the route to folder was not given as a relative path. Also the /static/ folder was already set via a hard-coded value in the AWS console at:
AWS > Elastic Beanstalk > > Configuration > Software Configuration > Virtual Path. I needed to change the value of /static/ to static/ here.
Finally the commands section was not required at all. The fixed python.config file (that works) is as follows:
option_settings:
aws:elasticbeanstalk:container:python:staticfiles:
"/templates/": "templates/"

Django; AWS Elastic Beanstalk ERROR: Your WSGIPath refers to a file that does not exist

I am using this tutorial:
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-django.html
I create the .ebextensions directory inside the root directory, and put this django.config file in it:
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: mysite/wsgi.py
I've also tried setting the path to mysite/mysite/wsgi.py because I saw that work somewhere but it did not help me.
Everywhere I look shows a different .config file with different arrangements, and I don't know where to go from here. How can I properly set my WSGIPath in Elastic Beanstalk?
[Solution]
1 eb config
2 Change the WSGIPath there from application.py to mysite/wsgi.py
That's It
I ran into a similar issue, and it seemed to resolve when I put .elasticbeanstalk in the same directory as .ebextensions, rather than having it be a child directory. Then I had to run eb config to fix the wsgi file that it was de facto picking up, and now I have a running app.
Make sure that .ebextensions isn't ignored. EB looks for .ignore file (.ebignore by default and if it doesnt exists but .gitignore does, it will use it) and deploy only the files that are not ignored. Had a similar issue with my local_settings.
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-configuration.html#eb-cli3-ebignore
I did not use console but GUI.
ERROR: Your WSGIPath refers to a file that does not exist.
where could be problem : Creating .zip file
select all : files of your project (not the project folder)
Note : weworkout is my django project (created by django-admin startproject
weworkout)
Right way : select all files
Wrong way : selecting project folder
Also this is the only change you have to do to your django project before uploading
weworkout/.ebextensions/django.config file contains
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: weworkout/wsgi.py
Note : .ebextensions is in same folder as manage.py
If you see the following error:
ERROR: Your WSGIPath refers to a file that does not exist.
Note the following:
EC2 (server) instances in EB (platform) run Apache.
Apache finds Python apps according to our WSGIPATH.
By default EB assumes the WSGI file is called application.py.
There are two ways of correcting this.
Option 1: Using environment-specific configuration settings
Run: $ eb config
Find the following config file “.elasticbeanstalk/src-test.env.yml.”
This file doesn’t actually exist locally; EB pulled it so that you can edit it.
If you save changes in this pseudo-file, EB will update the corresponding settings in your env.
If you search for the terms ‘WSGI’ in the file, you should find a config section resembling this:
aws:elasticbeanstalk:container:python:
NumProcesses: '1'
NumThreads: '15'
StaticFiles: /static/=static/
WSGIPath: application.py
Update the WSGIPath:
aws:elasticbeanstalk:container:python:
NumProcesses: '1'
NumThreads: '15'
StaticFiles: /static/=static/
WSGIPath: src/src/wsgi.py #src/src is an example. Do not just c&p.
If you save the file, EB will update the env config automatically.
The advantage to using the $ eb config method to change settings is that you can specify different settings per env.
Option 2: Using global configuration settings
To use this option, create a new file called /.ebextensions/02_python.config:
option_settings:
"aws:elasticbeanstalk:application:environment":
DJANGO_SETTINGS_MODULE: “src.settings" #src is an example.
"PYTHONPATH": "/opt/python/current/app/src:$PYTHONPATH" #src is an example.
"aws:elasticbeanstalk:container:python":
WSGIPath: src/src/wsgi.py #src is an example.
NumProcesses: 3
NumThreads: 20
"aws:elasticbeanstalk:container:python:staticfiles":
"/static/": "www/static/"
What’s happening?
DJANGO_SETTINGS_MODULE: "src.settings" - adds the path to the settings module.
"PYTHONPATH": "/opt/python/current/app/src:$PYTHONPATH" - updates our PYTHONPATH so Python can find the modules in our application.(Note that the use of the full path is necessary.)
WSGIPath: src/src/wsgi.py sets our WSGI Path.
NumProcesses: 3 and NumThreads: 20 - updates the number of processes and threads used to run our WSGI application.
"/static/": "www/static/" sets our static files path.
Run $ git commit (if necessary) and $ eb deploy to update these settings.
Check if your Django.config file was saved with the correct extension. I had the same issue and the problem was that the file was being saved as a TXT file instead of config file.

Amazon Elastic Beanstalk : how to set the wsgi path?

I practice set up Django under Elastic Beanstalk from there document.
But There is error.
ERROR Your WSGIPath refers to a file that does not exist.
My directory like this:
-djangoenv (where I use git)
- mysite
-manage.py
-mysite
-__init__.py
-settings.py
-urls.py
-wsgi.py
and My the .elasticbeanstalk/optionsettings.djapp file like this :
And .ebextensions/python.config like this , I don't know where to put this .try several times still not work . I try mysite/mysite/wsgi.py still not work
container_commands:
01_syncdb:
command: "django-admin.py syncdb --noinput"
leader_only: true
option_settings:
- namespace: aws:elasticbeanstalk:container:python
option_name: WSGIPath
value: mysite/wsgi.py
- option_name: DJANGO_SETTINGS_MODULE
value: mysite.settings
Please tell me how and where to set my wsgi path ??
Thank you very much!
I found that you have to restart the server for it to take these changes into consideration.
I spent ages changing and tweaking these options and nothing worked. Then when I went to the EB console and restarted the environment it worked.
In the server you are about to deploy the django application to elasticbean stalk. Run:
eb config
Then replace the application.py to mysite/wsgi.py and save the changes.
After the update, you may do:
git add.
git commit -m "some updates"
eb deploy
After successfully update the environment, you may view the changes in elasticbeanstalk, under your enviroment, go to the instance and check the setting in Configuration, then view the WSGIPath under Software Configuration.
Disclaimer: This information is valid until 4 November 2016. AWS may further change the setting.
The path specified should be relative to the .elasticbeanstalk directory.
The correct path should be mysite/mysite.wsgi.py. option_settings: is:
option_settings:
- namespace: aws:elasticbeanstalk:container:python
option_name: WSGIPath
value: mysite/mysite/wsgi.py
- option_name: DJANGO_SETTINGS_MODULE
value: mysite.settings
You have WSGIPath set to "application.py" but your WSGI file is "mysite/wsgi.py".
You should try
mysite.wsgi:application and make sure you are in the mysite first folder while deploying your application

Heroku app crashed after pushing small change. Very confused

I am using Heroku with python and Flask. My app was working fine until I updated a few lines in my python application file. The app runs fine locally, but I now have the following error when I try to access my app:
"An error occurred in the application and your page could not be served. Please try again in a few moments.
If you are the application owner, check your logs for details."
My logs look something like this:
2012-10-03T17:40:26+00:00 heroku[web.1]: Process exited with status 1
2012-10-03T17:40:26+00:00 heroku[web.1]: State changed from starting to crashed
2012-10-03T17:51:25+00:00 heroku[web.1]: State changed from crashed to starting
2012-10-03T17:51:26+00:00 heroku[web.1]: Starting process with command `python presentation.py`
2012-10-03T17:51:26+00:00 app[web.1]: ImportError: No module named site
I am also no longer able to run python through heroku:
Cinnas-MacBook-Pro:infinite-fortress-4866 cinna$ heroku run python
Running `python` attached to terminal... up, run.1
ImportError: No module named site
The next thing I have tried to do is check my environment variables:
Cinnas-MacBook-Pro:infinite-fortress-4866 cinna$ heroku config
=== infinite-fortress-4866 Config Vars
LANG: en_US.UTF-8
LD_LIBRARY_PATH: /app/.heroku/vendor/lib
LIBRARY_PATH: /app/.heroku/vendor/lib
PATH: /app/.heroku/venv/bin:/bin:/usr/local/bin:/usr/bin
PYTHONHASHSEED: random
PYTHONHOME: /app/.heroku/venv/
PYTHONPATH: /app/
PYTHONUNBUFFERED: true
However, when I try to look inside the library directories, I get something like this:
Cinnas-MacBook-Pro:infinite-fortress-4866 cinna$ heroku run ls /app/.heroku/vendor/lib
Running `ls /app/.heroku/vendor/lib` attached to terminal... up, run.1
ls: cannot access /app/.heroku/vendor/lib: No such file or directory
I am not sure where to proceed at this moment. I miss my app, please help!
Additional information:
The problems all started when I added the following lines to my app.py code:
#app.route('/my_fb_graph',methods=['GET','POST'])
def my_fb_graph():
return render_template('my_fb_graph.html')
When I pushed the code and the app no longer worked. I then removed these lines of code, pushed the code again, and still got the same errors. The next thing I did was to completely remove the app.py file and try to a small test code which still did not work.
The root of the problem seems to be the error:
2012-10-03T17:51:26+00:00 app[web.1]: ImportError: No module named site
I was able to fix the problem, but still dont know why it occurred in the first place!
After a lot of experimentation, I ended up setting up a completely new app on Heroku. I checked the environment variables in the new app and got the following:
Cinnas-MacBook-Pro:thawing-temple-4323 cinna$ heroku config
=== thawing-temple-4323 Config Vars
FACEBOOK_APP_ID: ***
FACEBOOK_SECRET: ***
PATH: bin:/usr/local/bin:/usr/bin:/bin
PYTHONUNBUFFERED: true
Checking my original app (the broken one), I realized that new environment variables were somehow added in my last push as indicated by my logs:
2012-10-04T04:20:04+00:00 heroku[api]: Add PYTHONUNBUFFERED, PYTHONPATH, PYTHONHOME, LANG, LD_LIBRARY_PATH, PATH, PYTHONHASHSEED, LIBRARY_PATH config by ***#***
and by checking my environment variables:
Cinnas-MacBook-Pro:infinite-fortress-4866 cinna$ heroku config
=== infinite-fortress-4866 Config Vars
LANG: en_US.UTF-8
LD_LIBRARY_PATH: /app/.heroku/vendor/lib
LIBRARY_PATH: /app/.heroku/vendor/lib
PATH: /app/.heroku/venv/bin:/bin:/usr/local/bin:/usr/bin
PYTHONHASHSEED: random
PYTHONHOME: /app/.heroku/venv/
PYTHONPATH: /app/
PYTHONUNBUFFERED: true
I removed these new variables with the command:
heroku config:remove PYTHONPATH PYTHONHOME LANG LD_LIBRARY_PATH PYTHONHASHSEED LIBRARY_PATH
and my app started to work again. I've been pushing more code, and this problem has not occurred again.
I am still really curious why/how these variables were added in the first place since all I did was do a git push.
I experienced a very similar problem yesterday (6th Dec. 2012). Out of the blue, every python invocation died with 'ImportError: No module named site'. Heroku support got back to me today and they say it's fixed on their end, so the following workaround shouldn't be required. I'll leave this here in case it helps someone else diagnose.
I checked my heroku config vars though, and there were no PYTHON* variables set. They were set as env vars at the shell level though:
$ heroku run set | grep PYTHON
PYTHONHASHSEED=random
PYTHONHOME=/app/.heroku/venv/
PYTHONPATH=/app/
PYTHONUNBUFFERED=true
/app/.heroku/venv was a non-existent directory. If I overrode PYTHONHOME with a config var, and pointed to where my virtualenv actually was, it all started working again:
$ heroku config:set PYTHONHOME=/app
/app appears to be a mount point for the project root directory. Digging through the history of the Python buildpack, it looks like when I started my project, everyone made their virtualenvs in the project root. Now new projects make virtualenvs in a venv/ subdirectory. Support said they were gradually rolling out a buildpack change, and I guess the checks for the old way of doing things didn't kick in for me.
Here's where to look for the buildpack internals:
https://github.com/heroku/heroku-buildpack-python/blob/master/bin/compile
This bit me, too. I'm not sure when it started. I don't believe it was in response to any change on my part, I just noticed Application Error on my site today, and found this in the logs:
2012-12-12T16:02:06+00:00 heroku[web.1]: State changed from crashed to starting
2012-12-12T16:02:09+00:00 heroku[web.1]: Starting process with command `aspen --network_address=:40856 --www_root=doc/ --project_root=doc/.aspen`
2012-12-12T16:02:10+00:00 app[web.1]: ImportError: No module named site
2012-12-12T16:02:11+00:00 heroku[web.1]: Process exited with status 1
2012-12-12T16:02:11+00:00 heroku[web.1]: State changed from starting to crashed
I had another release ready to go, so I just deployed as usual. After a git push heroku, the site is back up. My heroku config doesn't have the extra envvars listed above:
$ heroku config
=== aspen-io Config Vars
ASPEN_IO_SHOW_GA: yes
PATH: bin:/usr/local/bin:/usr/bin:/bin
PYTHONUNBUFFERED: true
Update: #kennethreitz pointed me to this:
Cannot import module site
This occurs when the configured environment variables don't match the
paths of the installed Python. When this occurs, it is because someone
purged an app's cache without understanding the above implications.
To fix, either purge the cache and update the configuration, or
restore the expected configurations (preferred).

Categories

Resources