簡體   English   中英

在標頭 Python 之前結束腳本輸出

[英]End of script output before headers Python


我在 python 中創建了 Hello world 腳本。 每次我嘗試運行它時,網絡瀏覽器都會向我發送錯誤 500

錯誤消息:標題之前的腳本輸出結束:test.py

腳本:

#!C:\Python35\python.exe

print("Content-Type: text/html")
print()
print("<TITLE>CGI script output</TITLE>")
print("<H1>This is my first CGI script</H1>")
print("Hello, world!")

這是 apache 錯誤輸出

End of script output before headers: test.py
AH01215: C:\\Python35\\python.exe: can't open file '%L': [Errno 2] No such file or directory: C:/xampp/cgi-bin/test.py

當我注意到一個有效的 python 腳本會打開一個窗口並顯示“Content-type: text/html\n\n”時,我遇到了這個錯誤,因為失敗的腳本打開了一個窗口但沒有顯示“Content-類型:文本/html\n\n"。

我在 main() 的第一行添加了 "print('Content-type: text/html\n\n') 並修復了它。

注意我使用 Geany 來測試腳本。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM