Forums

'unhanded exception' error when browsing to website

Hi,

I've set up my first web and and have configured the wsgi file (correctly I think). When I browse to my website however I get the above message. If I leave the wsgi unchanged from default I get the hello world message. Any ideas of what I'm doing wrong?

(Complete newbie here so please be gentle :) )

Many thanks

Philip

The best way to debug this kind of thing is to look at your server logs. There are links to them on the web app page; for the "unhandled exception" message, the one called something like "jingscrivvens.pythonanywhere.com.server.log" is likely to be the best place to look -- check out whatever's at the bottom and see if that points you in the right direction.

Thanks for that Giles. I checked the error log and it seems to be having trouble finding my settings file - here's the error message:

Could not import settings 'inverness_merchants_project.settings' (Is it on sys.path?): No module named inverness_merchants_project.settings

My .wysg file contains the following which all looks ok. What else do I need to check?

path = '/home/JingsCrivvens/the-merchant/inverness_merchants_project' if path not in sys.path: sys.path.append(path)

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

import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler()

Many thanks Phil

Can I take a look at your files? It might be easier to debug that way.

sure - do you need me to do anything to enable that?

Nope, just need your permission. Looking now...

OK, got it, I think. It looks like your app is Django 1.4+, and I see you have a virtualenv with 1.5.4, so I guess you've written the app for that version. What you need to do is set up your WSGI file to activate and use that virtualenv. This page has instructions on setting up a Django 1.5 web app on PythonAnywhere; you can skip most of it because you already have the virtualenv, but about halfway down there's a copy of a WSGI file that does what you need. You'll need to change the username and the name of the virtualenv in the appropriate places -- let me know if it's unclear what to do for that.

Thanks again for that Giles - made the changes to the wsgi file as suggested. I' now getting a slightly different error:

2013-11-22 08:16:19,221 :Traceback (most recent call last):
2013-11-22 08:16:19,221 :IOError: [Errno 2] No such file or directory: 'home/JingsCrivvens/.virtualenvs/theMerchant/bin/activate_this.py'

the usename and virtual environment look correct. Any ideas as to what I'm doing wrong?

Many thanks

Phil

Are you missing a leading slash in /home/JingsCrivvens?

home/JingsCrivvens/.virtualenvs/theMerchant/bin/activate_this.py

Should be

/home/JingsCrivvens/.virtualenvs/theMerchant/bin/activate_this.py

oooops you're right Harry - however I'm now getting:

:Traceback (most recent call last): 2013-11-22 09:09:29,303 : File "/var/www/jingscrivvens_pythonanywhere_com_wsgi.py", line 1 2013-11-22 09:09:29,303 : activate_this = '/home/JingsCrivvens/.virtualenvs/theMerchant/bin/activate_this.py' execfile(activate_this, dict(file=activate_this)) import os import sys path = '/home/JingsCrivvens/the-merchant/inverness_merchants_project' if path not in sys.path: sys.path.append(path) os.environ['DJANGO_SETTINGS_MODULE'] = 'inverness_merchants_project.settings' import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler() 2013-11-22 09:09:29,303 : ^ 2013-11-22 09:09:29,303 :SyntaxError: invalid syntax

I check and rechecked the file and it all looks ok - I must be missing something but I can't see what.

Thanks again

I think there's some kind of problem with the whitespace in your file. The way I read that traceback, it thinks the entire WSGI file is a single line.

Try going through it and deleting the trailing whitespace at the end of each line, and manually deleting and re-entering a carriage return on each one?

Hi Harry,

That appears to have been the problem ??!. Interestingly I always get presented with a single line when I go to edit any of the files?. Also I cant seem to copy and paste into the editor -- I've put this down to the setup on my local machine although all seemed to be ok yesterday?.

I'm now getting a db error when running the app:

database error: no such table: merchant_catalog

The app doesn't appear to be seeing the db although it is in what I think is the correct location. Even when I hard code the path the settings.py ie

/home/JingsCrivvens/the-merchant/theMerchant.db - I still get the error

any suggestions?

Sorry for all this hassle

Kind Regards

Phil

Hi Phil -- re: the single line in the editor -- which browser/OS are you using? Do you have JavaScript switched off, or perhaps some kind of ad-blocker?

Regarding the database problem, I agree that everything looks like it's there. Did you reload the web app after you changed your settings.py file?

Hi Giles,

I'm getting closer :) The db is now getting picked up although I seem to have a general path issue as I had to hard code the path to the db - as mentiond previously and I'm now getting a message that my base.html template cannot be found. My settings.py includes

PROJECT_PATH = os.getcwd()
TEMPLATE_PATH = os.path.join(PROJECT_PATH, 'templates')
STATIC_PATH = os.path.join(PROJECT_PATH,'static')
DATABASE_PATH = os.path.join(PROJECT_PATH, 'theMerchant.db')

which all works fine on my local machine. Do I need to change anything here to get it working on the remote server?

Thanks again for all your help

Phil

[edit by admin: code formatting]

Hi Phil,

Yup, there's one small change. On your local machine you're running your web app from a specific directory, but on PythonAnywhere it could be running in any directory -- so os.getcwd won't return the same value as it does locally.

It looks to me like you want PROJECT_PATH to point to the directory above the one that contains settings.py, so it's best to say that explicitly:

PROJECT_PATH = os.path.join(os.path.dirname(__file__), "..")

That should do the trick.

Giles

Thats brilliant Giles -- working now :) one last thing - the django admin interface isn't picking up the static content, I've set the url to: /static/admin/

and the directory to: /home/JingsCrivvens/.virtualenvs/theMerchant/lib/python2.7/site-packages/django/contrib/static/admin

Is this correct or does it need to change?

I think it should be /home/JingsCrivvens/.virtualenvs/theMerchant/lib/python2.7/site-packages/django/contrib/admin/static/admin

Thats it!! All working now :)

Thanks again for all your time and help

Phil

No problem! Glad it's working now.

hi JingsCrivvens

can you tell me how do u set static files in pythonanywhere

where did u put this path '/home/JingsCrivvens/.virtualenvs/theMerchant/lib/python2.7/site-packages/django/contrib/admin/static/admin' in settings.py or some where in webapp directory

@akhil - static files are set up on the Web tab. you set up a mapping between the URL you want (eg /static/) and the path to the files in your account (eg /home/my-username/my-project/static_folder/)