简体   繁体   English

输出上的Python WSGI错误

[英]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. 我的python已经很生锈了,因为我已经有一段时间没有使用它了,并且遇到了一个我无法解决的问题。

The python program should accept a form's data sent by a web page, and return some JSON response codes back to it. python程序应接受网页发送的表单数据,并向其返回一些JSON响应代码。 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] ...返回浏览器

[wsgi:error] ... {"errors": [1430360477881, 1430233459050]} [wsgi:error] ... {“错误”:[1430360477881,1430233459050]}

[wsgi:error] ... mod_wsgi (pid=1654): Exception occurred processing WSGI script '/tmp/mod_wsgi-localhost:8000:0/htdocs/'. [wsgi:error] ... mod_wsgi(pid = 1654):处理WSGI脚本'/ tmp / mod_wsgi-localhost:8000:0 / htdocs /'时发生异常。

[wsgi:error] ... TypeError: 'NoneType' object is not iterable [wsgi:error] ... TypeError:“ NoneType”对象不可迭代
... ...

Ok, Python is complaining that something it expects to be iterable is None. 好的,Python抱怨它期望可迭代的值是None。 But which iterable is Python complaining about in this function? 但是Python在此函数中抱怨的是哪个可迭代的? (Note that I am using mod_wsgi directly without any frameworks / modules). (请注意,我没有任何框架/模块就直接使用mod_wsgi)。

您需要返回响应:

return output(environ, start_response, info)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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