Re: small python cgi webserver

2006-11-05 Thread Norbert Kaufmann
Fabian Braennstroem wrote:
[...]
>>In your response (cgi-script) you have to divide the header from the
>>content '\r\n\r\n'.
> 
> 
> I am not sure, what that means!?  ... but it works :-)
> 

We are talking about HTTP, take a look at the HTTP response in version 1.1:
http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html#sec6

As you may see you separate the header of a response from the body by an
empty line, generated with CRLF.
Since one CRLF ends the line inside the header you need two of them.

Bye

Norbert
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: small python cgi webserver

2006-11-04 Thread Fabian Braennstroem
Hi Norbert,

* Norbert Kaufmann <[EMAIL PROTECTED]> wrote:
> Fabian Braennstroem wrote:
> [...]
>> 
>> Maybe, I understood something wrong, but I thought that the
>> above 'webserver' script would replace apache in my case; at
>> least I hoped!?
>> 
>
> It does. The 'ServerRoot' and 'DocumentRoot' directories are the
> directories you are starting your webserver in.
> Create a 'cgi' directory inside this and consider that you have to name
> it in the serverscript in relation to the serverroot!
>
> 
> cgi_directories=["/home/fab/Desktop/cgi-bin"]
> 
>
> This means you have to start your server inside directory '/'.

I tried this, but it does not help ... a wait, the leading
'/' is the problem. Thanks!
>
> If you start your server in your home dir '/home/fab' then you have to
> name your cgi_directories ['/Desktop/cgi-bin'].
>
> In your response (cgi-script) you have to divide the header from the
> content '\r\n\r\n'.

I am not sure, what that means!?  ... but it works :-)

Greetings!
 Fabian

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: small python cgi webserver

2006-11-04 Thread ArdPy

Fabian Braennstroem wrote:
> Hi,
>
> * ArdPy <[EMAIL PROTECTED]> wrote:
> >
> > Fabian Braennstroem wrote:
> >> Hi,
> >>
> >> I am looking for a small python script, which starts a small
> >> web server with python cgi support on a linux machine.
> >>
> >> I tried:
> >>
> >>
> >>   #!/usr/bin/env python
> >>   import sys
> >>   from CGIHTTPServer import CGIHTTPRequestHandler
> >>   import BaseHTTPServer
> >>
> >>   class MyRequestHandler(CGIHTTPRequestHandler):
> >>   # In diesem Verzeichnis sollten die CGI-Programme stehen:
> >>   cgi_directories=["/home/fab/Desktop/cgi-bin"]
> >>
> >>
> >>   def run():
> >>   # 8000=Port-Nummer
> >>   #   --> http://localhost:8000/
> >>   # Fuer http://localhost/
> >>   #   Port-Nummer auf 80 setzen
> >>   httpd=BaseHTTPServer.HTTPServer(('', 8000), MyRequestHandler)
> >>   httpd.serve_forever()
> >>
> >>   if __name__=="__main__":
> >>   print "Starting Server"
> >>   run()
> >>
> >> but when I want to test a small python cgi test file:
> >>
> >>
> >>   #!/usr/bin/python
> >>   # -*- coding: UTF-8 -*-
> >>
> >>   # Debugging für CGI-Skripte 'einschalten'
> >>   import cgitb; cgitb.enable()
> >>
> >>   print "Content-Type: text/html;charset=utf-8\n"
> >>   print "Hello World!"
> >>
> >> I just get the text and not the html output. The file's mode
> >> is 755.
> >>
> >> Is there anything wrong with the webserver script or do I do
> >> something completely wrong? Maybe, you have a different
> >> webserver script?
> >>
> >> Greetings!
> >>  Fabian
> >
> > Probably the server is not executing your CGI script. If it is the
> > Apache web server that you are using then just ensure the following
> > settings in your /etc/httpd/conf/httpd.conf file is exactly like
> > following:
> >
> > 
> > AllowOverride None
> > Options ExecCGI
> > Order allow,deny
> > Allow from all
> > 
>
> Maybe, I understood something wrong, but I thought that the
> above 'webserver' script would replace apache in my case; at
> least I hoped!?
>
> Greetings!
>  Fabian

Oh yes...Your script is supposed to replace apache. I tried with your
script on my pc and its working just fine. However the problem still is
that the server is taking your file to be a plain file rather than a
CGI script. Looking at CGIHTTPServer.is_cgi method might prove helpful.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: small python cgi webserver

2006-11-04 Thread Norbert Kaufmann
Fabian Braennstroem wrote:
[...]
> 
> Maybe, I understood something wrong, but I thought that the
> above 'webserver' script would replace apache in my case; at
> least I hoped!?
> 

It does. The 'ServerRoot' and 'DocumentRoot' directories are the
directories you are starting your webserver in.
Create a 'cgi' directory inside this and consider that you have to name
it in the serverscript in relation to the serverroot!


cgi_directories=["/home/fab/Desktop/cgi-bin"]


This means you have to start your server inside directory '/'.

If you start your server in your home dir '/home/fab' then you have to
name your cgi_directories ['/Desktop/cgi-bin'].

In your response (cgi-script) you have to divide the header from the
content '\r\n\r\n'.

HTH

Norbert
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: small python cgi webserver

2006-11-04 Thread Fabian Braennstroem
Hi,

* ArdPy <[EMAIL PROTECTED]> wrote:
>
> Fabian Braennstroem wrote:
>> Hi,
>>
>> I am looking for a small python script, which starts a small
>> web server with python cgi support on a linux machine.
>>
>> I tried:
>>
>>
>>   #!/usr/bin/env python
>>   import sys
>>   from CGIHTTPServer import CGIHTTPRequestHandler
>>   import BaseHTTPServer
>>
>>   class MyRequestHandler(CGIHTTPRequestHandler):
>>   # In diesem Verzeichnis sollten die CGI-Programme stehen:
>>   cgi_directories=["/home/fab/Desktop/cgi-bin"]
>>
>>
>>   def run():
>>   # 8000=Port-Nummer
>>   #   --> http://localhost:8000/
>>   # Fuer http://localhost/
>>   #   Port-Nummer auf 80 setzen
>>   httpd=BaseHTTPServer.HTTPServer(('', 8000), MyRequestHandler)
>>   httpd.serve_forever()
>>
>>   if __name__=="__main__":
>>   print "Starting Server"
>>   run()
>>
>> but when I want to test a small python cgi test file:
>>
>>
>>   #!/usr/bin/python
>>   # -*- coding: UTF-8 -*-
>>
>>   # Debugging für CGI-Skripte 'einschalten'
>>   import cgitb; cgitb.enable()
>>
>>   print "Content-Type: text/html;charset=utf-8\n"
>>   print "Hello World!"
>>
>> I just get the text and not the html output. The file's mode
>> is 755.
>>
>> Is there anything wrong with the webserver script or do I do
>> something completely wrong? Maybe, you have a different
>> webserver script?
>>
>> Greetings!
>>  Fabian
>
> Probably the server is not executing your CGI script. If it is the
> Apache web server that you are using then just ensure the following
> settings in your /etc/httpd/conf/httpd.conf file is exactly like
> following:
>
> 
> AllowOverride None
> Options ExecCGI
> Order allow,deny
> Allow from all
> 

Maybe, I understood something wrong, but I thought that the
above 'webserver' script would replace apache in my case; at
least I hoped!?

Greetings!
 Fabian

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: small python cgi webserver

2006-11-04 Thread ArdPy

Fabian Braennstroem wrote:
> Hi,
>
> I am looking for a small python script, which starts a small
> web server with python cgi support on a linux machine.
>
> I tried:
>
>
>   #!/usr/bin/env python
>   import sys
>   from CGIHTTPServer import CGIHTTPRequestHandler
>   import BaseHTTPServer
>
>   class MyRequestHandler(CGIHTTPRequestHandler):
>   # In diesem Verzeichnis sollten die CGI-Programme stehen:
>   cgi_directories=["/home/fab/Desktop/cgi-bin"]
>
>
>   def run():
>   # 8000=Port-Nummer
>   #   --> http://localhost:8000/
>   # Fuer http://localhost/
>   #   Port-Nummer auf 80 setzen
>   httpd=BaseHTTPServer.HTTPServer(('', 8000), MyRequestHandler)
>   httpd.serve_forever()
>
>   if __name__=="__main__":
>   print "Starting Server"
>   run()
>
> but when I want to test a small python cgi test file:
>
>
>   #!/usr/bin/python
>   # -*- coding: UTF-8 -*-
>
>   # Debugging für CGI-Skripte 'einschalten'
>   import cgitb; cgitb.enable()
>
>   print "Content-Type: text/html;charset=utf-8\n"
>   print "Hello World!"
>
> I just get the text and not the html output. The file's mode
> is 755.
>
> Is there anything wrong with the webserver script or do I do
> something completely wrong? Maybe, you have a different
> webserver script?
>
> Greetings!
>  Fabian

Probably the server is not executing your CGI script. If it is the
Apache web server that you are using then just ensure the following
settings in your /etc/httpd/conf/httpd.conf file is exactly like
following:


AllowOverride None
Options ExecCGI
Order allow,deny
Allow from all


-- 
http://mail.python.org/mailman/listinfo/python-list


small python cgi webserver

2006-11-04 Thread Fabian Braennstroem
Hi,

I am looking for a small python script, which starts a small
web server with python cgi support on a linux machine.

I tried:


  #!/usr/bin/env python
  import sys
  from CGIHTTPServer import CGIHTTPRequestHandler
  import BaseHTTPServer
  
  class MyRequestHandler(CGIHTTPRequestHandler):
  # In diesem Verzeichnis sollten die CGI-Programme stehen:
  cgi_directories=["/home/fab/Desktop/cgi-bin"]
  
  
  def run():
  # 8000=Port-Nummer
  #   --> http://localhost:8000/
  # Fuer http://localhost/ 
  #   Port-Nummer auf 80 setzen
  httpd=BaseHTTPServer.HTTPServer(('', 8000), MyRequestHandler)
  httpd.serve_forever()
  
  if __name__=="__main__":
  print "Starting Server"
  run()

but when I want to test a small python cgi test file:


  #!/usr/bin/python
  # -*- coding: UTF-8 -*-

  # Debugging fÃŒr CGI-Skripte 'einschalten'
  import cgitb; cgitb.enable()

  print "Content-Type: text/html;charset=utf-8\n"
  print "Hello World!"

I just get the text and not the html output. The file's mode
is 755.

Is there anything wrong with the webserver script or do I do
something completely wrong? Maybe, you have a different
webserver script?

Greetings!
 Fabian

-- 
http://mail.python.org/mailman/listinfo/python-list