1

I am a newbie in Python & web.py so excuse my ignorance. I had a script for a web page that was working, and then randomly stopped working. I've been at it for a few days and cant seem to figure the issue out.

I keep getting the following error:

127.0.0.1:49664 - - [05/Jul/2012 23:58:42] "HTTP/1.1 GET /" - 500 Internal Server Error 127.0.0.1:49664 - - [05/Jul/2012 23:58:43] "HTTP/1.1 GET /favicon.ico" - 404 Not Found Traceback (most recent call last): File "C:\Python27\lib\site-packages\web\application.py", line 239, in process return >self.handle() File "C:\Python27\lib\site-packages\web\application.py", line 230, in handle return >self._delegate(fn, self.fvars, args) File "C:\Python27\lib\site-packages\web\application.py", line 419, in _delegate cls = >fvars[f] KeyError: u'index'

Here is my Python script:

import web
from web import form
db = web.database(dbn='mysql', user='dbuser', pw='dbuser', db='database')
render = web.template.render('templates/')
urls = (
    '/', 'index',
    '/update/(\d+)', 'update'
)
app = web.application(urls, globals())
myform = form.Form(
    form.Radio('sentiment',[('1','Positive'),('3','Neutral'),('2','Negative'),('4','SPAM')],description='Sentiment',))

def insert_sentiment(id, sentimentvar):
    db.update('tweets', sentiment=sentimentvar, where="tweet_id=$id", vars=locals())

class update:
    def GET(self):
        tweets_index = db.select('tweets', where='sentiment is null', order='RAND()', limit=1)
        form = myform()
        return render.index(form, tweets_index)
        raise web.seeother('/')

    def POST(self, id):
        form = web.input()
        insert_sentiment(id, form.sentiment)
        raise web.seeother('/')

if __name__=="__main__":
    web.internalerror = web.debugerror
    app.run()

The template is stored in a 'templates' folder and is as follows:

$def with (form,tweets_index)
$for tweets in tweets_index:
        $tweets.tweet
        $tweets.normalized_tweet
<form action="/update/$tweets.tweet_id" method="post">
    $:form.render()
    <input type="submit" value="update"/>
</form>

If I change the name of the index page to something else, then that is what shows up in the error. Please help!

5
  • 2
    web.py makes developers cry :( Commented Jul 6, 2012 at 13:00
  • It says "404 not found" for favicon.ico. This is the little icon associated with an URL in a web browser and all web browsers try to fetch that file. What if you copy such an icon file into the root of the directory you're serving? Alternatively, you have to make sure that you recover gracefully from that get, but to get you started try to create this file. Commented Jul 6, 2012 at 13:05
  • Thanks for the advice on the favicon. I've seen this error all throughout development (when the script was working), so I dont think its whats causing the issue. I've just been too lazy to create one right now. Commented Jul 6, 2012 at 13:10
  • You're right.. the real error is " _delegate cls = >fvars[f] KeyError: u'index'" so "GET /" from your browser is converted to "GET /index" and there's no page called index (or index.htm?), right? Commented Jul 6, 2012 at 13:16
  • well, there is an index.html page in the templates folder. Commented Jul 6, 2012 at 13:22

1 Answer 1

5

You don't have a class index with a GET method

Sign up to request clarification or add additional context in comments.

2 Comments

You don't need to - web.py is pretty intransparent and uses a lot of dubious magic.
@Randy: Try something else than web.py next time. :) Flask is pretty good.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.