Using a global
in your get_subreddit
function looks wrong to me.
reddit_url = 'http://reddit.com/r/'
def get_subreddit(name):
global reddit_url
reddit_url += name
Every time, you run that function, you append the value of name
to a global reddit_url
.
- It starts as
http://reddit.com/r/
- run
get_subreddit("python")
and it changes tohttp://reddit.com/r/python
- run
get_subreddit("python")
again, and it changes tohttp://reddit.com/r/pythonpython
- at this point, the url is invalid, and you have to restart your server.
You probably want to change get_subreddit
so that it returns a url, and fetch this url in your function.
def get_subreddit(name):
return "http://reddit.com/r/" + name
# in your view
url = get_subreddit("python")
# now fetch url
There are probably other mistakes in your code as well. You can't really expect somebody on stack overflow to fix all the problems for you on a project of this size. The best thing you can do is learn some techniques for debugging your code yourself.
- Look at the full traceback, not just the final
SiteError
. See what line of your code the problem is occurring in. - Add some logging or print statement, and try and work out why the
SiteError
is occurring. - Are you trying to download the url that you think you are (as I explained above, I don't think you are, because of problems with your
get_subreddit
method).
Finally, I recommend you make sure that the site works on your dev machine before you move on to deploying it on python anywhere. Deploying can cause lots of headaches all by itself, so it's good to start with an app that's working before you start.
Good luck :)