Flask-脚本'app.cgi'中格式错误的标头:标头错误 [英] Flask - malformed header from script 'app.cgi': Bad header

查看:116
本文介绍了Flask-脚本'app.cgi'中格式错误的标头:标头错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在对Flask中的python脚本进行AJAX调用. python脚本通过jsonify返回响应对象.

I am making an AJAX call to my python script in Flask. The python script is returning a response object through jsonify.

python脚本部署在Apache24中.

return jsonify({"responseList": response}) # here response is a list

在我的Web浏览器中,我收到错误-500-内部服务器错误. 在Apache日志中,我看到此错误malformed header from script 'app.cgi': Bad header

In my web browser I get the Error - 500 - Internal server error. In the Apache logs, I see this error malformed header from script 'app.cgi': Bad header

我阅读了

I read here that we need to give a new line between the header and the body to avoid this error. Is that really needed with jsonify or is there a way to give a new line, as jsonify adds the header on its own.

请提出建议. 谢谢.

推荐答案

我相信您需要按如下所示编写返回行:

I believe you need to write your return line as follows:

import Response from flask
import json
...

return Response(json.dumps({"responseList": response}),  mimetype='application/json')

这篇关于Flask-脚本'app.cgi'中格式错误的标头:标头错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆