[英]Python WSGI Error on Output
我的python已经很生锈了,因为我已经有一段时间没有使用它了,并且遇到了一个我无法解决的问题。
python程序应接受网页发送的表单数据,并向其返回一些JSON响应代码。 一切正常,除了发送数据时:
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] ... {“错误”:[1430360477881,1430233459050]}
[wsgi:error] ... mod_wsgi(pid = 1654):处理WSGI脚本'/ tmp / mod_wsgi-localhost:8000:0 / htdocs /'时发生异常。
[wsgi:error] ... TypeError:“ NoneType”对象不可迭代
...
好的,Python抱怨它期望可迭代的值是None。 但是Python在此函数中抱怨的是哪个可迭代的? (请注意,我没有任何框架/模块就直接使用mod_wsgi)。
您需要返回响应:
return output(environ, start_response, info)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.