WebBrowser不显示pythont CGI程序的完整输出

2024-09-26 18:16:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用Python3和CGI在我的Web浏览器上显示总线。但是浏览器不知何故没有得到HTML脚本的漏洞。以下是我的代码(Python):

#!/usr/bin/python3

import time
import dvb
import sys

stop = 'Hauptbahnhof'
time_offset = 0
num_results =5
city = 'Dresden'

output=dvb.monitor(stop, time_offset, num_results, city)
#print(output)
print("Content-type:text/html;charset=utf-8\r\n\r\n")
print("<html><body>")
i=0
for items in output:
    print("<p>")
    print(str(output[i]['line']))
    print(str(output[i]['direction']))
    print(str(output[i]['arrival']))
    print("</p>")
    i=i+1
print("</html></body>")

当我在控制台中执行它时,我得到以下输出:

Content-type:text/html;charset=utf-8


<html><body>
<p>
64
Striesen
0
</p>
<p>
79
Übigau
1
</p>
<p>
64
Kaditz, Riegelplatz
2
</p>
<p>
4
Laubegast
3
</p>
<p>
9
Prohlis
4
</p>
</body></html>

在浏览器中调用该文件时,我得到以下源代码:

<html><body>
<p>
64
Striesen
0
</p>
<p>
79

所以Soucecode没有正确传输,但是为什么呢

更多技术信息:
-虚拟盒
-ubuntu-18.04.1-dekstop-amd64

编辑: 我使用apache2/2.4.29。
她是我的apache2虚拟主机配置:

<VirtualHost *:80>
    ServerName busLinien
    ServerAdmin jofri@localhost
    DocumentRoot /var/www/busLinien
    <Directory /var/www/busLinien>
            AllowOverride None
            Allow from all
            Require all granted
            Options ExecCGI
            AddHandler cgi-script .py
    </Directory>
    ErrorLog /var/log/apache2/error.log
    LogLevel warn
    CustomLog /var/log/apache2/access.log combined
    ServerSignature On


Tags: importlogoutputtimevarhtml浏览器body

热门问题