Python WSGI Error on Output

谁都会走 提交于 2020-01-05 08:06:19

问题


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:


You need to return the response:

return output(environ, start_response, info)


来源:https://stackoverflow.com/questions/29959267/python-wsgi-error-on-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!