CGI-problem
Jason Orendorff
jason at jorendorff.com
Thu Jan 24 03:14:07 EST 2002
olav viken wrote:
> Hi!
>
> I'm having a problem passing the '#-character' to a cgi-script.
>
> The cgi script is invoked with a url as this:
>
> http:/myserver/script.py?link="T:/test.htm#Mark"
The CGI script is behaving correctly; it's the URL that's incorrect.
Your browser is behaving correctly by *not* sending the # sign
(or anything after it) to the server.
Special characters like quotes, colons, and the # symbol must
be encoded if you want to include them in a URL. You can encode
them with the urllib.quote() function.
>>> import urllib
>>> print urllib.quote('"T:/test.htm#Mark"')
%22T%3A/test.htm%23Mark%22
So this is the correct URL:
http:/myserver/script.py?link=%22T%3A/test.htm%23Mark%22
It looks strange, but the CGI module understands it and will
automatically convert the encoded characters back to normal
characters for you. Try it.
## Jason Orendorff http://www.jorendorff.com/
More information about the Python-list
mailing list