【问题标题】:Error while running python with xammp server使用 xampp 服务器运行 python 时出错
【发布时间】:2021-04-23 10:19:51
【问题描述】:

我是使用 xammp 服务器运行 python 的新手。我已经按照此链接Running Python scripts with Xampp 完成了在 xammp 服务器中运行 python 所需的所有设置。在尝试运行我的代码时,我总是遇到错误。

**Internal Server Error 服务器遇到内部错误或配置错误,无法完成您的请求。

请通过 postmaster@localhost 联系服务器管理员 告知他们此错误发生的时间,以及您采取的措施 在此错误之前执行。

有关此错误的更多信息可能在服务器错误中可用 记录。**

我的错误日志这样说: [2021 年 1 月 19 日星期二 10:29:34.529875] [cgi:error] [pid 11652:tid 1860] [client ::1:50570] 来自脚本“python.py”的标头格式错误:标头错误:Hello World

我也在附上我的文件的代码。

#! C:\Users\"UserName"\AppData\Local\Programs\Python\Python39\python.exe
print("Content-Type: text/html\n\n")
import cgi

print("Hello Python")

我已尽我所能寻找解决方案,但没有任何帮助。请帮我找到解决方案。谢谢

【问题讨论】:

    标签: python xampp


    【解决方案1】:

    更新 \n\n 以使用回车 (\r\n\r\n),并添加另一个 in。

    这应该使您的 HTTP 标头有效,因为它们可能没有正确终止。

    编辑:也可以试试多行打印指令如

    print "Content-type: text/html"
    print ""
    

    这会将正文解释为标题(从未终止),因此正确终止它应该可以修复它。

    【讨论】:

    • print("Content-Type: text/html\r\n\r\n") 添加了这个但同样的错误
    • 你有没有研究过像 Flask @smartF 这样的框架
    猜你喜欢
    • 2012-12-26
    • 2018-07-11
    • 1970-01-01
    • 2014-10-31
    • 2018-05-21
    • 2018-07-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多