脚本index.py中的标头格式错误 [英] malformed header from script index.py Bad header

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

问题描述

我想在apache2(ubuntu 14.04)服务器中运行python代码.我已按照以下步骤操作并出现错误:

I want to run python code in apache2(ubuntu 14.04) server. I have followed these steps and getting Error:

第1步:

配置1:我在

/var/www/cgi-bin

配置2:我已经编辑了/etc/apache2/sites-available/000-default.conf

Configuration 2 : I have edited /etc/apache2/sites-available/000-default.conf

Alias /cgi-bin /var/www/cgi-bin
<Directory "/var/www/cgi-bin">
Options Indexes FollowSymLinks ExecCGI
AddHandler cgi-script .cgi .py
Allow from all
</Directory>

<Directory /var/www/cgi-bin>
Options All
</Directory>

第2步:

我的python脚本是:index.py

and my python script is: index.py

#!/usr/bin/env python
import cgi;
import cgitb;cgitb.enable()

print "Content-Type: text/plain\n"

print "<b>Hello python</b>"

第3步:

当我使用以下方法通过chrome浏览器运行时: 网址: http://localhost/cgi-bin/index.py

When i ran through chrome browser using: URL : http://localhost/cgi-bin/index.py

第4步:

我在错误日志中收到此错误

I am getting this Error in error-log

malformed header from script 'index.py': Bad header: Hello Python

推荐答案

您应该以\r\n结尾标题,然后必须打印出另一个\r\n来表明身体快到了.

You should end your header with \r\n, then you must print out yet another \r\n to signal that the body is coming.

(换句话说,因为标头从未终止,所以将您的身体解释为标头)

(In other words, it's interpreting your body as a Header because the headers were never terminated)

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

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