---
title: "python3.7 “malformed header from script”错误"
author: "Cash"
date: "2019-03-05T10:57:00Z"
tags: []
categories: ["编程语言"]
slug: "python3-7-malformed-header-from-script"
draft: false
lastmod: "2019-03-05T10:57:00Z"
id: 2438434
url: "https://cash.iteye.com/blog/2438434"
---

最近测试python编程登陆，发现apache总是报错
[Tue Mar 05 10:26:58.837624 2019] [cgi:error] [pid 3096:tid 1192] [client 127.0.0.1:58566] malformed header from script 'login_check.py': Bad header: 1, referer: http://127.0.0.1/login.html

查阅很多文章需要把头部输出调整为 print("Content-type:text/html\n\n")

但始终未果，最后在日志中发现错误重要信息：
 Bad header: 1,     #这个“1”是因为引用了自建的函数py文件中多输出了一个测试“1”字符，导致目前的py文件调用时，在print("Content-type:text/html\n\n")执行前，输出了一个“1”导致整个输出头部失败！

故障排查了1天时间，才发现这个问题！