输出上的Python WSGI错误 [英] Python WSGI Error on Output
问题描述
我的python已经很生锈了,因为我已经有一段时间没有使用它了,并且遇到了一个我无法解决的问题.
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程序应接受网页发送的表单数据,并向其返回一些JSON响应代码.一切正常,除了发送数据时:
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]
错误日志显示:
...
[wsgi:error] ...返回浏览器
...
[wsgi:error] ... BACK TO THE BROWSER
[wsgi:error] ... {错误":[1430360477881,1430233459050]}
[wsgi:error] ... {"errors": [1430360477881, 1430233459050]}
[wsgi:error] ... mod_wsgi(pid = 1654):处理WSGI脚本'/tmp/mod_wsgi-localhost:8000:0/htdocs/'时发生异常.
[wsgi:error] ... mod_wsgi (pid=1654): Exception occurred processing WSGI script '/tmp/mod_wsgi-localhost:8000:0/htdocs/'.
[wsgi:error] ... TypeError:"NoneType"对象不可迭代
...
[wsgi:error] ... TypeError: 'NoneType' object is not iterable
...
好吧,Python抱怨它期望可迭代的东西是None.但是Python在此函数中抱怨的是哪一个可迭代的事物? (请注意,我直接使用mod_wsgi而不使用任何框架/模块).
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)
这篇关于输出上的Python WSGI错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!