Forums

Error running WSGI application

I cant seem to deploy succesfully. What I got from error log is:

Error running WSGI application  ImportError: cannot import name
'prode' File "/var/www/samaproject_pythonanywhere_com_wsgi.py", line
77, in <module> from prodesama import prode as application

[edit by admin: formatting]

What's the code that you have in your WSGI file?

The code in my wsgi is:

import os
import sys


path = '/home/samaproject/prodesama'
if path not in sys.path:
    sys.path.append(path)

os.environ['DJANGO_SETTINGS_MODULE'] = 'prodesama.settings'

sys.path.append('/home/samaproject/prodesama')
from prodesama import prode as application

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()



HELLO_WORLD = """<html>
<head>
    <title>Python Anywhere hosted web application</title>
</head>
<body>
<h1>Hello, World!</h1>
<p>
    This is the default welcome page for a
    <a href="https://www.pythonanywhere.com/">PythonAnywhere</a>
    hosted web application.
</p>
<p>
    Find out more about how to configure your own web application
    by visiting the <a href="https://www.pythonanywhere.com/web_app_setup/">web app setup</a> page
</p>
</body>
</html>"""


def application(environ, start_response):
    if environ.get('PATH_INFO') == '/':
        status = '200 OK'
        content = HELLO_WORLD
    else:
        status = '404 NOT FOUND'
        content = 'Page not found.'
    response_headers = [('Content-Type', 'text/html'), ('Content-Length', str(len(content)))]
    start_response(status, response_headers)
    yield content.encode('utf8')

OK. So you appear to be defining three different WSGI applications in there. What kind of website have you written? If it's a Django one, then you don't need most of that code. You just need this:

import os
import sys

path = '/home/samaproject/prodesama'
if path not in sys.path:
    sys.path.append(path)

os.environ['DJANGO_SETTINGS_MODULE'] = 'prodesama.settings'

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

Thank you!! That worked perfectly

No problem, glad to help!