I can’t seem to see what’s wrong with this code, yet I get an IndentationError when I run the script.
import web
import json
urls = (
'/(.*)', 'handleRequest'
)
app = web.application(urls, globals())
class handleRequest:
def GET(self, method_id):
if not method_id:
return json.dumps({'ok':0})
else:
return json.dumps({'ok': method_id})
def POST(self):
i = web.input()
pass
if __name__ == "__main__":
app.run()
This is the console error messages I get when I attempt to run the script:
>>> def POST(self):
File "<stdin>", line 1
def POST(self):
^
IndentationError: unexpected indent
>>> i = web.input()
File "<stdin>", line 1
i = web.input()
^
I have checked the indentation – and its the same 4 spaces I have used throughout the file – am I missing something?!
You’re not “running the script”, you’re typing it into the REPL. Save the contents to a file and execute the file via e.g.
python somescript.py.