简体   繁体   中英

Python WSGI Error on Output

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).

您需要返回响应:

return output(environ, start_response, info)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM