[Tutor] Redirect from a CGI script
Paulino
paulino1 at sapo.pt
Sat Jan 20 16:22:59 CET 2007
Still doesn't work.
This should be a server issue, once I use a very basic server:
'from BaseHTTPServer import HTTPServer
'from CGIHTTPServer import CGIHTTPRequestHandler
'HTTPServer(("localhost", 80),CGIHTTPRequestHandler).serve_forever()
I tryed also with the Karrigel embeded server and nothing happened...
I tryed all the sugestions from Andre with no succes.
The cgi script as only these two lines:
'print "Content-type: text/html\r\n"
'print "Location: http://python.org/\r\n\r"
I have a Win Xp pro machine with Python2.5.
Paulino
> On Sat, 2007-01-20 at 02:10 +0000, Paulino wrote:
>
>> Thank you Andre,
>>
>> well it doesn't work either!
>>
>
> This works,
>
> #!/usr/bin/python
> print "Location: http://python.org/\r\n\r"
>
> as does this
>
> #!/usr/bin/python
> print "Content-type: text/html\r"
> print "Location: http://python.org/\r\n\r"
>
>
> Tested using Apache on Linux. A redirect should have a 3xx status.
> Apache saw the location header and fixed the status to be 302. My
> browser (firefox) received the 302 status with the new location and
> requested the new URL.
>
> Each header line should be separated by \r\n. A Python print on linux
> will only output \n. In actual practice, that appears to work OK.
> either the browsers tolerate the missing \r or Apache fixes the data
> stream.
>
> Firefox plugins called tamperdata and liveheaders can be very helpful
> for debugging these kinds of interactions.
>
> Get the redirect to a real web site working. Then fix it to redirect to
> your script. Use tamperdata to see what is going on if you have trouble
> making it work.
>
>
>> Paulino
>>
>>> Andre Engels escreveu:
>>> 2007/1/18, Paulino <paulino1_at_sapo.pt at .syntax-error>:
>>> How can i redirect to another URL from a python CGI script.
>>>
>>> Is's suposed to be as simply as:
>>>
>>> print "Location : http://newurl "
>>> It's not working.
>>>
>>> this simple code does't work - < redir.pyw>
>>> 'print "Content-Type:text/html\n\n"
>>> 'print "Location : /cgi-bin/ecodiv.pyw "
>>> 'print
>>>
>>> I use CGIHTTPServer, the server script is as follows:
>>>
>>> 'from BaseHTTPServer import HTTPServer
>>> 'from CGIHTTPServer import CGIHTTPRequestHandler
>>> 'HTTPServer(("localhost", 80),
>>> CGIHTTPRequestHandler).serve_forever()
>>>
>>> instead of redirecting, it only prints
>>> 'Location : /cgi-bin/ecodiv.pyw' inthe
>>> browser
>>>
>>>
>>> I haven't tested it, but I think I had a similar error recently, and
>>> that was solved by removing the \n\n at the end of the Content-Type
>>> line. You could try that.
>>>
>>>
>>>
>>>
>>>
>>>
>>> --
>>> Andre Engels, andreengels at gmail.com
>>> ICQ: 6260644 -- Skype: a_engels
>>>
>> _______________________________________________
>> Tutor maillist - Tutor at python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070120/70f0a2f3/attachment-0001.htm
More information about the Tutor
mailing list