Question

I'm trying to get POST/GET data in my python script. I'm using the web.py framework and below is my code:

import web

form = web.input()
mydata = form.mydata

This is the error output im getting:

File "script.py", line 22, in <module>
    form = web.input()
  File "/usr/local/lib/python2.7/dist-packages/web.py-0.37-py2.7.egg/web/webapi.py", line 330, in input
    out = rawinput(_method)
  File "/usr/local/lib/python2.7/dist-packages/web.py-0.37-py2.7.egg/web/webapi.py", line 291, in rawinput
    e = ctx.env.copy()
AttributeError: 'ThreadedDict' object has no attribute 'env'

(I'm used to getting these variables in PHP and am not sure why im having a hard time with python)

Was it helpful?

Solution

In web.py you have to define a class for the URL and functions for GET and POST within it. So then in the POST function of the URL class you can set form = web.input(). Below is a quick example of this structure.

class Index:
    def GET(self):
        #Your GET code here...

    def POST(self):
        input = web.input()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top