When attempting to run a Python 3.4 CGI script on Microsoft Windows, specifically using Python 3.4 and Windows 7 along with the Python 3 HTTPServer module, I encountered an issue where the script could not load the CSS stylesheet file. The output from my HTTPServer was as follows:
C:\Users\aliv>E:\winService\serv.py
serving at port 8000
127.0.0.1 - - [11/Jan/2015 14:11:24] "GET /cgi-bin/winserv.py HTTP/1.1" 200 -
127.0.0.1 - - [11/Jan/2015 14:11:24] command: C:\Python34\python.exe -u C:\Users
\aliv\cgi-bin\winserv.py ""
...
HTTP Code snippet:
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8>
<title>Message Page</title>
<link rel="stylesheet" type="text/css" href="./winserv.css" />
...
HTTP Server code:
#!/usr/bin/python3
from http.server import HTTPServer, CGIHTTPRequestHandler
class Handler(CGIHTTPRequestHandler):
cgi_directories = ["/cgi-bin"]
PORT = 8000
httpd = HTTPServer(("", PORT), Handler)
print("serving at port", PORT)
httpd.serve_forever()
Python CGI script code:
#!/usr/bin/python3
import cgi
import cgitb
cgitb.enable()
print("Content-type:text/html\n\n")
ff = open('./cgi-bin/winserv.html', mode='r', encoding='utf_8')
aa = ff.read()
print(aa.format(message='!'))
ff.close()
Chrome log message:
Resource interpreted as Stylesheet but transferred with MIME type text/plain: "http://localhost:8000/cgi-bin/winserv.css".