我正在尝试在localhost
. 作为第一步,我在 python 中创建了一个服务器脚本
#!/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 移动到服务器目录中的子目录中。