2

My python has become quite rusty as I haven't used it for quite a while and am stuck with an issue I am not able to figure out.

The python program should accept a form's data sent by a web page, and return some JSON response codes back to it. Everything works fine except when the data is sent:

def application(environ, start_response):
    """ Process the form data, spit out the reponse """

    # code here extracts the form 
    # data and the response code is 
    # stored in info

    # everything done, output now
    output(environ, start_response, info)


def output(environ, start_response, info):
    
    # debug
    print >> environ['wsgi.errors'], "BACK TO THE BROWSER"

    feedback = json.dumps(info)
    
    # debug
    print >> environ['wsgi.errors'], feedback
    
    status = "200 OK"
    headers = [('Content-Type', 'application/json; charset=UTF-8'), ('Content-Length', str(len(feedback)))]
    start_response(status, headers)
    return [feedback]

The error log says:

...
[wsgi:error] ... BACK TO THE BROWSER

[wsgi:error] ... {"errors": [1430360477881, 1430233459050]}

[wsgi:error] ... mod_wsgi (pid=1654): Exception occurred processing WSGI script '/tmp/mod_wsgi-localhost:8000:0/htdocs/'.

[wsgi:error] ... TypeError: 'NoneType' object is not iterable
...

Ok, Python is complaining that something it expects to be iterable is None. But which iterable is Python complaining about in this function? (Note that I am using mod_wsgi directly without any frameworks / modules).

1 Answer 1

3

You need to return the response:

return output(environ, start_response, info)
Sign up to request clarification or add additional context in comments.

3 Comments

So basically, for WSGI the input and the output both have to be from the same function (application() here, in the case of mod_wsgi)?
WSGI requires application to take the request and return an iterable response.
More details can be found in PEP 3333

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.