Forums

Server error 500 when using sqlite3

I'm working on my website and I've started hosting it with PythonAnywhere, and I have the entire website working great... except for one part: My blog. The blog half works, since I can go to certain page numbers, but I can't go to the root blog page without getting a Server Error 500. I'm using sqlite3 for my blog.

Here is the website URL: sonic2kk.pythonanywhere.com/ Here is the website blog URL: sonic2kk.pythonanywhere.com/blog/

Here is my settings.py file: http://pastebin.com/JPBNDfQc

If you go to "http://sonic2kk.pythonanywhere.com/blog/1", you'll see a test blog entry I made, so the path to my sqlite3 db is correct. I've ran syncdb I don't know how many times, and I am definitely refreshing the website each time I made a change.

Any idea why I'm getting this problem, and could you suggest a way for me to fix it?

Thanks!

Hmm, normally I'd suggest you take a look at the error log, which is where PythonAnywhere puts stack traces for any unhandled exceptions, but I see that that is empty right now. The server error page you're getting looks like it's being generated by your web framework -- it's not one of ours -- and you mention a settings.py file, so I'm guessing you're using Django. What do you get if you set DEBUG to True in the settings?

I get an error. Here is the copy/paste version of the error. It says I have a pagination error, but it runs fine on my own local server. I installed the pagination plugin, and I'm almost sure it was the correct one.

http://pastebin.com/Wn8tJ6fs

A syntax error like that makes me suspect that we have a Python mismatch problem here. Which version of Python are you using on your local server? It looks like you've chosen Python 3.4 here.

I'm using the same version: Python 3.4.1. I'm using Django 1.6.5 here, and Django 1.6.5 on my local server too. I'm 100% sure. I thought this too. Here is my Python prompt on my local PC:

Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 00:54:21) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information.

import django django.VERSION (1, 6, 5, 'final', 0)

And here is my Python prompt when running a bash prompt here on PythonAnywhere:

Python 3.4.1 (default, May 26 2014, 01:12:52) [GCC 4.8.1] on linux Type "help", "copyright", "credits" or "license" for more information.

import django django.VERSION
(1, 6, 5, 'final', 0)

So I'm not entirely sure where this problem is stemming from. Thanks for all your help so far :D

OK. So the error is in the pagination module, so I think we can assume that's wrong. How did you install it?

I installed it with the following command: pip3.4 install --user django-pagination

I ran the command again to 100% make sure that it was installed. I confirmed that it was the same module on my local PC as well. The project is almost identical on my local PC (by "almost" I mean I needed to change some of the mainsite project templates for static files a little, but other than that there's no change). I have confirmed that I have pagination listed as an installed app in my settings.py, and it is also listed as middleware.

If you're using a virtualenv, you want to install django-pagination into your virtualenv, not into your --user packages.

source virtualenvwrapper.sh
workon your-virtualenv
pip install django-pagination

I had a virtualenv that I used as a test, but I'm not using it. I ran the commands anyway, and I got (what I'm almost sure is) the same error: http://pastebin.com/QybKi03z

I refreshed the server, and I refreshed it again to make sure it was definitely throwing the same error.

I got it to work. I had to go through a hole convoluted plan to get it to work. Eventually, I found this: /home/sonic2kk/.local/lib/python3.4/site-packages/pagination/templatetags/

^That was the location of my pagination installation. I went into that directory, looked for pagination_tags.py, went to line 225 and found this: KeyError, AttributeError

^That was valid syntax is older versions of Python. I went into that file and changed "KeyError, AttributeError", to "KeyError as AttributeError". Just a heads up to anyone having this issue ^^ I have no idea why it works on my local server, because I can assure you I am using Python version 3.4 (I had to jump through a few hoops to get it to work on my local server). It works now. Thank you to everyone who helped me :D PythonAnywhere is truly awesome, and I can't wait to host with them (the free plan worked wonders for just getting setup, but now it's time I actually use a plan that is suitable for my needs).

Have a great day!

It's awesome that you've got it fixed, but that's really very odd! I assume that the KeyError, AttributeError was in an except block? That's definitely Python 2 syntax, like you say, so it's really weird if the same thing works on your local machine. Perhaps one of the hoops you had to jump through patched the pagination module up in some very non-obvious way. Some installers can be strange like that...

Just one suggestion, assuming it was in an except handler that you found the issue -- the syntax

except KeyError, AttributeError:

in Python 2 was probably meant to mean "catch both KeyErrors and AttributeErrors". Replacing that with "KeyError as AttributeError" would change the semantics to "catch only KeyErrors, and when you do, bind the error to the local variable called AttributeError, masking the type".

What it should probably be is

except (KeyError, AttributeError):

...which has the correct semantics. Here's the PEP for the syntax change, in case you're interested.