【发布时间】:2015-04-30 04:50:55
【问题描述】:
我的 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,没有任何框架/模块)。
【问题讨论】: