我试图在localhost
上显示图像。作为第一步,我已经建立在PythonLocalhost无法显示图像
#!/usr/bin/env python
import BaseHTTPServer
import CGIHTTPServer
import cgitb; cgitb.enable() ## This line enables CGI error reporting
server = BaseHTTPServer.HTTPServer
handler = CGIHTTPServer.CGIHTTPRequestHandler
server_address = ("", 8000)
handler.cgi_directories = ["/"]
httpd = server(server_address, handler)
httpd.serve_forever()
一个服务器脚本的图像被放置在该脚本执行相同的目录中。 随后在浏览器中输入http://localhost:8000/test.jpg
。
浏览器失败,错误要呈现的图像: The image "http://localhost:8000/test.jpg" cannot be displayed because it contains errors.
服务器脚本引发像
File "/usr/lib/python2.7/CGIHTTPServer.py", line 253, in run_cgi
os.execve(scriptfile, args, env)
OSError: [Errno 8] Exec format error
我试图显示文本错误和服务器正常工作与大量的实例。除了它无法加载图像。我哪里错了?
问题解决了。我将test.jpg移动到 服务器目录中的一个子目录中。
我绝对需要在html上显示图像以及几条短信。该图像是在执行python脚本后生成的,因此需要CGIHttpServer。如何处理这种情况? SimpleHTTP在浏览器上显示图像,但我需要CGIHttp来生成它。 – Vikram
把CGI脚本放在一个子目录中并从那里提供它?默认情况下,它看起来像是如果你把它放在cgi-bin中,它会做你想做的。 –