symlinks with python3 http.server.CGIHTTPRequestHandler

Chris Angelico rosuav at gmail.com
Tue Jan 11 06:59:04 EST 2022


On Tue, Jan 11, 2022 at 6:17 AM Nat Taylor <nattaylor at gmail.com> wrote:
>
> Is it possible to get http.server.CGIHTTPRequestHandler to run a symlink-ed
> script?
>
> In the example below, GET /cgi-bin/test.py results in a 404 because it is a
> symlink.
>
> % mkdir -p test/cgi-bin
> % cd test
> % vi test.py
> % chmod +x test.py
> % ln -s test.py cgi-bin

I just noticed something. This might not produce the effect you want;
a symlink aims at a specific named target, and if you use a relative
path, it's relative to the directory containing the symlink, not the
directory you were in when you created it. What happens if, instead,
you do this:

% cd cgi-bin
% ln -s ../test.py .

? Conversely, can you, with whichever setup you're looking at, read
the source code for the script by catting it from cgi-bin? It might be
that the link is actually unreadable or pointing to the wrong place.

ChrisA


More information about the Python-list mailing list