This question (Python CGIHTTPServer Default Directories) details how to set paths for location of cgi-bin files for Python CGIHTTPServer. From testing this, it seems that you cannot mix .py and .html files in the same folder: in cgi-bin it processes .py files fine, but asked to serve a static html file I get
127.0.0.1 - - [08/Jan/2017 10:51:22] "GET /dev.html HTTP/1.1" 200 -
Traceback (most recent call last):
File "/usr/lib/python2.7/CGIHTTPServer.py", line 248, in run_cgi
os.execve(scriptfile, args, env)
OSError: [Errno 8] Exec format error
127.0.0.1 - - [08/Jan/2017 10:51:22] CGI script exit status 0x7f00
Is this the real intended behaviour, or am I missing something? The sparse and opaque documentation says "The class will however, run the CGI script, instead of serving it as a file, if it guesses it to be a CGI script. Only directory-based CGI are used — the other common server configuration is to treat special extensions as denoting CGI scripts."
How do I do "treat special extensions as denoting CGI scripts". What method or setting do I use, or which magic words do I utter? Or is this just an ineptly worded tip-off that I just can't do it?
I'm only using this for quick tests, and while I could restructure to separate .py and .html files I have other constraints that would make this a painful exercise.
I took oryginal
is_cgi()
fromCGIHTTPServer.py
and add two elementsCGIHTTPServer.
inCGIHTTPServer._url_collapse_path(self.path)
to use it outside fileCGIHTTPServer.py
and more important: checking extension
but it could be done better.
I didn't use
because server may execute scripts in other languages if you need - ie.
Perl
,PHP
,Bash
, etc.Code: