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 CGIHTTPRequestH andler
import BaseHTTPServer
class MyRequestHandle r(CGIHTTPReques tHandler):
# 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=BaseHTTPS erver.HTTPServe r(('', 8000), MyRequestHandle r)
httpd.serve_for ever()
if __name__=="__ma in__":
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=ut f-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 6 2417
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 CGIHTTPRequestH andler
import BaseHTTPServer
class MyRequestHandle r(CGIHTTPReques tHandler):
# 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=BaseHTTPS erver.HTTPServe r(('', 8000), MyRequestHandle r)
httpd.serve_for ever()
if __name__=="__ma in__":
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=ut f-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:
<Directory "/var/www/cgi-bin">
AllowOverride None
Options ExecCGI
Order allow,deny
Allow from all
</Directory>
Hi,
* ArdPy <ar****@gmail.c omwrote:
>
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 CGIHTTPRequestH andler import BaseHTTPServer
class MyRequestHandle r(CGIHTTPReques tHandler): # 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=BaseHTTPS erver.HTTPServe r(('', 8000), MyRequestHandle r) httpd.serve_for ever()
if __name__=="__ma in__": 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=ut f-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:
<Directory "/var/www/cgi-bin">
AllowOverride None
Options ExecCGI
Order allow,deny
Allow from all
</Directory>
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
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!
<quote>
cgi_directories =["/home/fab/Desktop/cgi-bin"]
</quote>
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
Fabian Braennstroem wrote:
Hi,
* ArdPy <ar****@gmail.c omwrote:
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 CGIHTTPRequestH andler
import BaseHTTPServer
class MyRequestHandle r(CGIHTTPReques tHandler):
# 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=BaseHTTPS erver.HTTPServe r(('', 8000), MyRequestHandle r)
httpd.serve_for ever()
if __name__=="__ma in__":
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=ut f-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:
<Directory "/var/www/cgi-bin">
AllowOverride None
Options ExecCGI
Order allow,deny
Allow from all
</Directory>
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.i s_cgi method might prove helpful.
Hi Norbert,
* Norbert Kaufmann <no*****@akumak un.dewrote:
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!
<quote>
cgi_directories =["/home/fab/Desktop/cgi-bin"]
</quote>
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
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/...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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Will Stuyvesant |
last post by:
Can you give a commandline example how to do XML Validation (checking
against a DTD) with Python? Not with 4Suite or other 3rd party
libraries, just the Python standard distribution. I have Python 2.2
but can upgrade to 2.3 beta if needed.
I am looking for something like:
"
$ python validate.py myxmlfile.xml mydtd.dtd
"
|
by: Carlos Andrade |
last post by:
I have a working python script that takes in content from a form,
cleans it up, adds html formatting and then places it into my
index.html page on my server. When I had index.html set up as :
-rw-rw-r-- 1 carlos wheel 3517 Aug 4 09:51 index.html
I could not write back to the file,
Traceback (most recent call last):
File "/usr/local/www/cgi-bin/bob.py", line 24, in ?
file=open("../data/index.html","w")
IOError: Permission denied:...
|
by: Bulba! |
last post by:
I'll soon start development of a specialized small app and need
to choose GUI for it.
I have narrowed the choice to wxPython/PythonCard and QT/PyQT
(buying commercial licenses is not a big problem, the company
would pay for it).
Which is better for this kind of application? I mean, looking
from purely technological and long-term development aspects
and ignoring licensing issues:
|
by: Venkat B |
last post by:
Hi folks,I have a webserver based on mini_httpd
v1.19(http://www.acme.com/software/mini_httpd/).I'd like to run some
python-based CGI scripts via this webserver on an RH9 system.In theory, with
the right env settings, Ishould be able to launch mini_httpd like so:
mini_httpd -c *.pyand be able to run scripts like so:
http://fqdn/simple.pyUsing info from (python) sys.path, multiple
get_config_var(..)s and sys.executable, Iwas able to build...
|
by: llothar |
last post by:
Hello,
as the subject says, for an embedded application i need a 100% pure
python webserver that can talk to a FCGI process (which runs ruby on
rails). Of couse it also must be able to use simple CGI.
Please don't ask why i want a python webserver for a ruby application.
I just need it.
| |
by: nicolasg |
last post by:
Hi folks, I have accomplished to make a python program that make some
image manipulation to bmp files.
I now want to provide this program as a web service. A user can visit a
site and through a web interface he should upload the file to the web
server , the server then will do the image process with the python
program I have wrote and when it finish the user must get the image
file back .
My question is how difficult is to set up a web...
|
by: dalebryan1 |
last post by:
I am working on a task to display a wireless network nodes using
Google Earth (GE) with KML network links. I am using a simple python
webserver (see code below) to serve up the python scripts as KML
output to GE for this.
import BaseHTTPServer
import CGIHTTPServer
class Handler(CGIHTTPServer.CGIHTTPRequestHandler):
cgi_directories =
httpd = BaseHTTPServer.HTTPServer(('',8000), Handler)
|
by: timotoole |
last post by:
Hi all,
I'm trying to get python to work with cgi for a small intranet site,
however even a simply "hello world test isn't working". Here is the
test file:
#!/usr/bin/python
# -*- coding: UTF-8 -*-
# enable debugging
|
by: timotoole |
last post by:
Hi all,
On a (sun) webserver that I use, there is python 2.5.1 installed. I'd
like to use sqlite3 with this, however sqlite3 is not installed on the
webserver. If I were able to compile sqlite using a sun machine (I
normally use linux machines) and place this in my lunix home account
would I be able to use python and sqlite?
Any thoughts? I know its a bit of a stretch ...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |