Your WSGIPath refers to a file that does not exist - amazon-web-services

I'm trying to upload my Flask application to AWS however I receive an error on doing so:
Your WSGIPath refers to a file that does not exist.
After doing some digging online I found that in the .ebextensions folder, I should specify the path. There was not a .ebextensions folder so I created one and added the following code to a file named settings.config:
option_settings:
"aws:elasticbeanstalk:container:python":
WSGIPath: project/application.py
the WSGIPath is the correct path to the application.py file so I'm not sure what raises this error. Am I changing the WSGIPath right, is there a better way or is there an issue with something else which causes this to happen? Thanks.

There's a lot of configuration issues that can arise with Flask deployed on AWS. I was running into a similar issue as you, so I can at least show you what I did to resolve the WSGI error.
First, apparently you can do this without the .ebextensions folder (see this post here. and look at davetw12's answer. However, be aware that while this works, I'm not entirely sure that davetw12's conclusion about .ebextensions is correct, based on some of the comments below). Instead, (in the Terminal), I navigated to my project at the same level as my .elasticbeanstalk directory and used the command eb config. This will open up a list of options you can set to configure your beanstalk application. Go down through the options until you find the WSGI path. I notice you have yours set to project/application.py, however, this should not include the folder reference, just application.py. Here is how it looks on my Mac in the terminal (WSGI path is near the bottom).
Note that once you get that set, EB will probably redeploy. That's fine. Let it.
Once you get that set, go into your application.py file and make sure you call your app application. For example, mine looks like this:
from flask import Flask
from flask import render_template
application = Flask(__name__)
#application.route('/')
#application.route('/index')
def index():
return render_template('index.html',
title='Home')
This took away the WSGI path error - although I still had to fix some other issues following this :-) But that is a different set of questions.

If anyone here is doing via AWS Console (GUI), modify the configuration and put your script name in WSGIPath as below.
I'm giving bonus hints if you are newer.
You should match the script name and the Flask object too.
Common mistake: When you're compressing the source code, you need to
select the files and compress, not the folder. (make sure you have the
.py in the root of the zip)
from flask import Flask
application = Flask(__name__)
#application.route("/")
def hello():
return "Hello"
if __name__ == "__main__":
application.run()

I had the same message, but for a very stupid reason.
Apparently, when I cloned the repo to my Windows PC and then pushed back the changes, somewhere along the way Windows changed ".ebextensions" folder to "ebextensions" (dropping the leading ".").
So when I renamed back the folder to ".ebextensions" in the master repo, everything started working again perfectly.

For me the problem was I had misspelled a filename:
I wrote: ..ebextensions/django.conf
When I needed: ..ebextensions/django.config
This cost me about 3 hours of my life today. The trouble was that the AWS error is misleading, because the "WSGIPath" it refers to is not the file above, but some invisible default.

In my case trying many solutions didn't solve the issue but changing WSGIPath from
option_settings:
"aws:elasticbeanstalk:container:python":
WSGIPath: project_name/application_name.py
to
option_settings:
"aws:elasticbeanstalk:container:python":
WSGIPath: project_name.wsgi
worked like a charm. Here is the file structure:
├── manage.py
├── mysite ***
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py ***
├── myvenv
│ └── ...
└── requirements.txt

Related

Install custom package (wheel) in MWAA

We are trying to install python package that can be shipped in plugins.zip for MWAA environment and added the reference in requirements.txt as described in the docs but we are still seeing the error file not found.
directory structure
├── README.md
├── dags
│   └── dummy.py
├── plugins
│   └── dummy-wheel-0.1.0-py3-none-any.whl
└── requirements.txt
The contents of requirements.txt
/usr/local/airflow/plugins/dummy-wheel-0.1.0-py3-none-any.whl
From here I have just created a zip file containing dummy-wheel-0.1.0-py3-none-any.whl and push it to S3://<bucket_name>/plugins.zip
Followed instructions here https://aws.amazon.com/premiumsupport/knowledge-center/mwaa-install-custom-packages/
What am I missing?
You may utilize BashOperator to list the directory /usr/local/airflow/plugins/ to verify whether the file is present there. While zipping, the whl file is supposed to be in the root path for it to be available in /usr/local/airflow/plugins/. Whereas if zipping a folder (eg. plugins), the extracted path will vary accordingly (eg. /usr/local/airflow/plugins/plugins/).
#mad_
Yeah I would try listing the contents of /usr/local/airflow/plugins first:
ls_airflow_plugins = BashOperator(
task_id="ls_airflow_plugins",
bash_command="ls -laR /usr/local/airflow/plugins",
dag=dag,
priority_weight=300,
)
Also, some things to try are:
put the actual plugins.zip file in a plugins/ folder that is at the same level as dag/ folder.
Before zipping the whl file, make sure you have given 755 file permissions (chmod 755 command)
at the top of your requirements.txt file, include:
--find-links /usr/local/airflow/plugins
--no-index
Hope one of these fixes it, lmk of questions
#mad_ Can you explain where you are seeing the file not found error?
If you zip packages and then edit/save your environment to point to the plugins.zip file, enable logging in the monitoring section before you re-deploy. The scheduler CloudWatch log will list packages that were installed (or errors that occurred). That may point you in the right direction.
The other thing to check is dependencies. If your package depends on a certain version of a package that MWAA already installs, you may need to include that dependency too.

django admin base.css cannot be found

I have an openedx instance which works fine with just an strange issue. for those who aren't familiar with openedx it's a learning management system written in django.
The issue:
trying to access django admin from http://mydomain.tld/admin shows the login page properly but with two static files, unfortunately one of them (base.f4e3330c1326.css) is not on the file system and the request for its loading ends with a HTTP 404 Not Found response.
looking at the static directory, there are 3 related files:
├── base.5af66c1b1797.css
├── base.css
├── base.d01c565630c2.css
caclulating the base.css md5 checksum:
user#host: ~$ md5sum /edx/var/edxapp/staticfiles/studio/admin/css/base.css
5af66c1b1797cb8f865b443cea0dcc17 /edx/var/edxapp/staticfiles/studio/admin/css/base.css
using django shell to retrive the path to the files:
>>> from django.contrib.staticfiles.templatetags.staticfiles import static
>>> static('admin/css/base.css')
'/static/studio/admin/css/base.f4e3330c1326.css'
I have collected static files more than ten times but it doesn't fixed.
my similar instance somewhere else has not this problem and I'm realy confused with it. could you please help me to debug this?
PS: I don't know about webpack but I think they started to use it recently and I think it should have some relation to my issue...

Openshift wrapper vs. project repo

I've tried to find a concrete answer for this but failed. I'm rather new to openshift, django and git so I hope it's not too trivial and not a duplicate.
The situation is as follows:
1. I'm developing a Django based web application and source control it using git on a private bitbucket repo. I have my regular django application source tree as needed.
2. I wish to deploy my app on openshift which comes with a different directory tree. I've been able to successfully run this quickstart:
git://github.com/rancavil/django-openshift-quickstart.git
Basically what I try to achieve is a wrapper directory (and git project) which is based on the repo specified in #2. Within this wrapper one of the subdirectories (wsgi/my_project) should be based on my private repo specified in #1.
I wish to be able to pull recent changes from the private repo and then push and deploy to openshift these changes.
Any help would be greatly appreciated!
I was also struggling with openshift structure. But there is no need for doing the staff like you have proposed.
You can have any structure of a project you want. Openshift will need just wsgi/application or wsgi.py as an entry point. I think that having one more file in your project is hardly a problem.
My current structure for a project (got it running recently) is following:
|- .openshift (directory for build and deployment hooks like syncdb or collectstatic commands)
|- custom_project (directory that is you django project)
\- templates
|- settings.py
|- urls.py
|- manage.py
|- requirements.txt
|- wsgi.py
There is really no need to have project under wsgi folder. However there are few more pitfalls to be aware of. Like creating static folder or setting .htaccess for static files.
Including my wsgi.py:
#!/usr/bin/python
import os
import logging
try:
virtenv = os.environ['OPENSHIFT_PYTHON_DIR'] + '/virtenv/'
virtualenv = os.path.join(virtenv, 'bin/activate_this.py')
execfile(virtualenv, dict(__file__=virtualenv))
except (IOError, KeyError):
pass
os.environ.setdefault("DJANGO_SETTINGS_MODULE", 'custom_project.settings')
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
I have used a lot of resources to make my project running on openshift so I'm also including them for other.
bitbucket and openshit repos: Can I use my existing git repo with openshift?
Slides with necesary steps: http://appsembler.com/blog/paas-bakeoff-comparing-stackato-openshift-dotcloud-and-heroku-for-django-hosting-and-deployment/
And the most important one, the really well written step-by-step tutorial: http://www.paascheatsheet.com/#Introduction

Setting up Django on AWS Elastic Beanstalk: WSGIPath not found

I've been trying for several days now to set up Django under Amazon Web Services' Elastic Beanstalk. I think the problem I'm hitting is this one:
ERROR - Your WSGIPath refers to a file that does not exist.
I followed the tutorial here and all goes well until the end of Step 6, but I can't for the life of me get anything to display other than the generic Elastic Beanstalk page from Step 5, #2. When I run
./manage.py runserver
on my local machine, everything works as it should, but I can't get that page to deploy. I first tried with a small Django site I wrote myself. It didn't work, so I deleted everything I'd done and tried again, that didn't work, so I deleted all that and tried again with a fresh django install. I tried that a bunch of times fiddling with little things, but I think I'm missing something major.
I added a python.config file as described in this tutorial.
Here's my file structure:
-.git/
-.mysite/
-myapp/
-__init__.py
-models.py
-tests.py
-views.py
-mysite/
-__init__.py
-settings.py
-urls.py
-wsgi.py
-.ebextensions/
-python.config
-manage.py
-mysite.db
-requirements.txt
From my settings.py:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'mysite.db',
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': '',
}
}
Here's python.config:
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
- option_name: AWS_SECRET_KEY
value: <This is my secret key>
- option_name: AWS_ACCESS_KEY_ID
value: <This is my access key>
Is there another place I need to define my WSGIPath? Is there a way to do it through the AWS console? Should I just skip EB altogether and use EC2 directly?
From https://forums.aws.amazon.com/thread.jspa?messageID=396656&#396656
The ".ebextensions" directory must be in the root level directory of your application, but from the log output, the directory is instead in the "mysite/.ebextensions" directory. So for example, after following the django tutorial in the docs when you run "git aws.push" your root directory would look like this:
.
├── .ebextensions
│ └── python.config
├── .elasticbeanstalk
│ ├── config
├── .git
├── .gitignore
├── manage.py
├── mysite
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
└── requirements.txt
Instead of this:
.
└── mysite
├── .ebextensions
├── .elasticbeanstalk
├── .git
├── .gitignore
├── manage.py
├── mysite
└── requirements.txt
Find .elasticbeanstalk/optionsettings.your-app-name in your app's root directory. Search for WSGIPath and make sure it's the path you intend. It looks like it defaults to application.py.
I had the same problem ("Your WSGIPath refers to a file that does not exist"), and finally found a solution:
The problem: I was downloading the bundle of the project directly from GitHub ("Download Zip"), which maybe had an improper structure.
The solution: I properly zip the files, without the main folder, using the Compress command. (cf http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features.deployment.source.html).
Note: At first, I was searching in the wrong direction, because EB was also showing this message: Error occurred during build: Command 01_migrate failed.. So I though the files, including the *.config, were correctly located.
Solution: using EBCLI
open eb config
For me it showed WSGIPath: application.py
Now Change it to
WSGIPath: my_app/wsgi.py
save and deploy.
Ok, here's what worked for me after trying a million things. You have to run eb update in order to update the environment.
So make sure .elasticbeanstalk/optionsettings.whatever-env has WSGIPath set to what you want it, and make sure .ebextensions/whatever.config has this:
option_settings:
- namespace: aws:elasticbeanstalk:container:python
option_name: WSGIPath
value: whatever/wsgi.py
Then run eb update and it should work. Remember you have to set the alias to make sure your eb command actually works. For example:
alias eb="python2.7 ../AWS-ElasticBeanstalk-CLI-2.6.3/eb/linux/python2.7/eb"
I had the same issue after following AWS's docs to the dot. What I did to avoid it was initialize an application through the EB CLI step by step, without using the command the AWS docs instructed (~/ebdjango$ eb init -p python2.7 django-tutorial), and creating an environment step by step as well. The steps I took in the EB CLI are the following:
Initialize Application
eb init
Select a default region
Enter Application Name (used default by pressing enter)
Confirmed that I am using Python
Selected Python version compatible with my local environment
Set up SSH
Create Environment
eb create
Enter Environment Name (used default by pressing enter)
Enter DNS CNAME prefix (used default by pressing enter)
Select a load balancer type (I selected classic by entering 1)
After Environment is created I use eb config to open EB's config file to confirm that the path to my WSGI is what it should be:
aws:elasticbeanstalk:container:python:
NumProcesses: '1'
NumThreads: '15'
StaticFiles: /static/=static/
WSGIPath: path/to/wsgi.py
If any changes are made, make sure you save the file and confirm that everything is squared up by entering eb open in your terminal to open a browser window using the domain name specified in previous steps.

Django custom commands not showing up on Heroku

I’m having a problem when using django custom commands on Heroku.
On my local machine, the custom command appears in help if I run ./manage.py help and running ./manage.py deletedphotos runs it too.
All the init.py files are there and the settings are also correct, i.e. there are not major config differences between my local and Heroku instances.
Now, when I put it on Heroku, it does not show up. All my other non-default commands are there: ping_google that comes from installing sitemap.xml support and commands for south migrations. But for some reason, my self written commands do not show up.
I’ve also sent a support request to Heroku, but haven’t heard back from them in a few days, so I thought I’d post here as well, maybe someone has had any similar problems.
The deletedphotos.py file contents are pretty much like this if that matters anything:
from django.core.management.base import BaseCommand, CommandError
from foo.app.models import *
class Command(BaseCommand):
help = 'Delete photos from S3'
def handle(self, *args, **options):
deleted_photos = Photo.objects.filter(deleted=True).exclude(large='', small='', thumb='')
self.stdout.write('Found %s photos\n' % str(len(deleted_photos)))
I’ve tried checking all the correct python paths etc, but not 100% if I’m not missing something obvious.
I was actually able to find a solution. The INSTALLED_APPS had my local app referenced, but for some reason it was not working as intended.
My app is in: /name/appname/ and having 'name.appname' in INSTALLED_APPS was working fine in local setup.
Yet, on Heroku, I had to change the reference to just 'appname' in INSTALLED_APPS and all started working magically.
Your home directory needs to be on your Python path. A quick and unobtrusive way to accomplish that is to add it to the PYTHONPATH environment variable (which is generally /app on the Heroku Cedar stack).
Add it via the heroku config command:
$ heroku config:add PYTHONPATH=/app
That should do it! For more details:
http://tomatohater.com/2012/01/17/custom-django-management-commands-on-heroku/
I had this problem too, found the answer here: Django Management Command ImportError
I was missing an __init__.py file in my management folder. After adding it everything worked fine.
Example:
qsl/
__init__.py
models.py
management/
__init__.py
commands/
__init__.py
news.py
jobs/
__init__.py
news.py
tests.py
views.py