Skip to content Skip to sidebar Skip to footer

Why Do I Get A KeyError?

This is my code: import web import json urls = ( '/', 'index' '/runs', 'runs' ) app = web.application(urls, globals()) class index: def GET(self): render = web

Solution 1:

You forgot a comma:

urls = (
    '/', 'index'
#               ^
    '/runs', 'runs'
)

Without the comma, Python concatenates the two consecutive strings, so you really registered:

urls = (
    '/', 'index/runs', 'runs'
)

and you have no such function in your globals() dictionary.

If I add in the comma your code works.


Solution 2:

Your code has a typo:

urls = (
    '/', 'index', # missing comma
    '/runs', 'runs'
)

Post a Comment for "Why Do I Get A KeyError?"