473,624 Members | 2,566 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

a little more help with python server-side scripting

I contacted my domain host about how Python is implemented on their
server, and got this response:

-------------------
Hello John,

Please be informed that the implementation of python in our server is
through mod_python integration with the apache.

These are the steps needed for you to be able to run .py script directly
from browser for your webpage:

1. Please use the below mentioned path for python:
#!/usr/bin/env python

Furthermore, update us with the script path, so that we can set the
appropriate ownership and permissions of the script on the server.

If you require any further assistance, feel free to contact us.
-----------------------

Unfortunately, I don't completely understand what it is I need to do
now. Where do I put the path they mentioned? And what do they mean by my
script path?
Feb 22 '06 #1
37 2465
John Salerno wrote:
I contacted my domain host about how Python is implemented on their
server, and got this response:

-------------------
Hello John,

Please be informed that the implementation of python in our server is
through mod_python integration with the apache.

These are the steps needed for you to be able to run .py script directly
from browser for your webpage:

1. Please use the below mentioned path for python:
#!/usr/bin/env python

Furthermore, update us with the script path, so that we can set the
appropriate ownership and permissions of the script on the server.

If you require any further assistance, feel free to contact us.
-----------------------

Unfortunately, I don't completely understand what it is I need to do
now. Where do I put the path they mentioned? And what do they mean by my
script path?

The Python tutorial should fill in the blanks
(http://www.python.org/doc/tut/node4.html): 2.2.2 Executable Python Scripts

On BSD'ish Unix systems, Python scripts can be made directly executable,
like shell scripts, by putting the line

#! /usr/bin/env python

(assuming that the interpreter is on the user's PATH) at the beginning
of the script and giving the file an executable mode. The "#!" must be
the first two characters of the file. On some platforms, this first line
must end with a Unix-style line ending ("\n"), not a Mac OS ("\r") or
Windows ("\r\n") line ending. Note that the hash, or pound, character,
"#", is used to start a comment in Python.
This answers your first question. Put the #! bit at the top of your
..py script. This way the web server will know how to run the script.
The script can be given a executable mode, or permission, using the
chmod command:

$ chmod +x myscript.py


And this answers your second. Your host needs to know the path to your
script so they can use chmod to make it executable.

--Ben

Feb 22 '06 #2
John Salerno wrote:
I contacted my domain host about how Python is implemented on their
server, and got this response:

-------------------
Hello John,

Please be informed that the implementation of python in our server is
through mod_python integration with the apache.

These are the steps needed for you to be able to run .py script directly
from browser for your webpage:

1. Please use the below mentioned path for python:
#!/usr/bin/env python

Furthermore, update us with the script path, so that we can set the
appropriate ownership and permissions of the script on the server.

If you require any further assistance, feel free to contact us.
-----------------------

Unfortunately, I don't completely understand what it is I need to do
now. Where do I put the path they mentioned? And what do they mean by my
script path?


Don't worry, it looks as though they don't completely understand either :-)

Fortunately they've given you the information you need to run CGI
scripts. Try installing this script in your cgi-bin directory as test.py
(you may have to set it executable):

#!/usr/bin/env python
#
import os
print "Content-Type: text/plain"
print
for t in os.environ.item s():
print "%s=%s" % t

If it runs when you access http://yourdomain/cgi-bin/test.py it looks
like you're good to go!

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/

Feb 22 '06 #3
Ben Cartwright wrote:
The script can be given a executable mode, or permission, using the
chmod command:

$ chmod +x myscript.py


And this answers your second. Your host needs to know the path to your
script so they can use chmod to make it executable.


Where does this line go? Just at the top as well?
Feb 22 '06 #4
Steve Holden wrote:
Fortunately they've given you the information you need to run CGI
scripts. Try installing this script in your cgi-bin directory as test.py
(you may have to set it executable):


Thank you! I desperately needed to test it, and that seemed to work. I
didn't have to make it executable though. I wonder why?
Feb 22 '06 #5
John Salerno wrote:
Ben Cartwright wrote:

The script can be given a executable mode, or permission, using the
chmod command:

$ chmod +x myscript.py


And this answers your second. Your host needs to know the path to your
script so they can use chmod to make it executable.

Where does this line go? Just at the top as well?


Nope. I presume you can log in to your web server using ssh or telnet or
similar. In which case you do so. Then use the commands

cd {wherever}/cgi-bin
chmod +x test.py

to make the script executable, and therefore recognised as a proper
script by Apache.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/

Feb 22 '06 #6
John Salerno wrote:
Steve Holden wrote:

Fortunately they've given you the information you need to run CGI
scripts. Try installing this script in your cgi-bin directory as test.py
(you may have to set it executable):

Thank you! I desperately needed to test it, and that seemed to work. I
didn't have to make it executable though. I wonder why?


Probably because the cgi-bin directory is specially marked to contain
executables. If you drop the script in another directory you will almost
certainly just see the source of the script. Making it executable
*might* cause it to run, but that would depend on exactly how your
server is configured.

Certainly my sites all have a line like

ScriptAlias /cgi-bin/ "c:/apache/cgi-bin/"

in the httpd.conf file. ScriptAlias tells Apache that the files in the
directory are scripts. The first argument is the address in web-space,
the second the address on disk.

You'll find you can affect *some* configuration items by creating files
called .htaccess in your web content directories, but that's a ways down
the road yet.

If the script ran, you will now know waht version of Apaceh you're
running with!

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/

Feb 22 '06 #7
Steve Holden wrote:
Where does this line go? Just at the top as well?


Nope. I presume you can log in to your web server using ssh or telnet or
similar. In which case you do so. Then use the commands

cd {wherever}/cgi-bin
chmod +x test.py

to make the script executable, and therefore recognised as a proper
script by Apache.


I'm afraid I still don't understand. I guess this step isn't necessary,
since the script seemed to run anyway, but I'd like to know this anyway.
The way I log into my server space is by an FTP program, so I don't see
an occasion to actually *type* in any kind of commands.
Feb 22 '06 #8
Steve Holden wrote:
If the script ran, you will now know waht version of Apaceh you're
running with!


Well, the script did seem to run, but I'm still not sure if this is what
I'm ultimately after. This allows me to run Python script files, which
is good, but what I really want to do is write bits of Python code in my
HTML files (as a means to include headers and footers, for example). So
these bits of Python code will basically be like a PHP include()
function that calls another HTML file which contains the header/footer
HTML to insert into the calling file. This type of situation doesn't
involve calling external Python scripts.

Maybe I can just try this also and see if it works, but I don't know the
code to use to write such an include statement. What would the
equivalent of this be in Python:

<?php include('file.h tml'); ?>

Thanks.
Feb 22 '06 #9
John Salerno wrote:
Steve Holden wrote:

If the script ran, you will now know waht version of Apaceh you're
running with!

Well, the script did seem to run, but I'm still not sure if this is what
I'm ultimately after. This allows me to run Python script files, which
is good, but what I really want to do is write bits of Python code in my
HTML files (as a means to include headers and footers, for example). So
these bits of Python code will basically be like a PHP include()
function that calls another HTML file which contains the header/footer
HTML to insert into the calling file. This type of situation doesn't
involve calling external Python scripts.

Maybe I can just try this also and see if it works, but I don't know the
code to use to write such an include statement. What would the
equivalent of this be in Python:

<?php include('file.h tml'); ?>

Thanks.


There are various ways you can do this, each of which depends on having
a particular framework in place. Since your web service provider tells
you that mod_python is available it's likely that you'll be able to use
PSP (one of several beasts known as "Python Server Pages").

This is briefly described (for a flavor of the technology) in

http://www.python.org/pycon/dc2004/papers/14/

by the author of mod_python. If you like what you see then take a look
at the full mod_python documentation, at

http://www.modpython.org/live/current/doc-html/

Note that purists might suggest this isn't the best way to use Python on
the web. If it gets you where you want to be, feel free to ignore them :-)

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/

Feb 22 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3423
by: Ron Stephens | last post by:
I posted to my web site a fun little program called merlin.py today. Please keep in mind that I am a hobbyist and this is just a little hack, if you look at the code you will see that it is still possible to write spaghetti code, even with Python. I apologize, and I do intend to clean up the code, but it may take awhile. For now it works, with some bugs. It is a composite of a few scripts. The first, based on a script Max M uploaded to...
4
7168
by: Marc | last post by:
Hi all, I am trying to write an application where I need the ability to open an Excel spreadsheet and do basic read/write, insert rows, and hide/unhide rows. Using win32com I have been able to get the basics down as well as some examples displaying how to simply read and write. But the next step appears exponential. I haven never done anything in VB, so any and all concepts and commands are completely foreign. I have been digging...
2
1502
by: Python Baby | last post by:
I'm about to try a little test project in Python, but want to make sure I'm on the right foot. Any advice appreciated before I start this. MOST important : I want to make sure I'm not just re-inventing the wheel, if there's a library out there that does this exact thing already. SERVER: Has some protected files, not in a webroot, that I want to let the client
1
1719
by: Chuck Amadi | last post by:
A little help has anyone used the email-dir.py Email Module ,I have downloaded the example and would like some pointers to get it going . For example Have I got to add any parameters to python script or Do I just use the command line. Cheers
5
3625
by: iminal | last post by:
I am trying to make a very simple program and am very new to the whole programming thing. my program is supposed to ask a user for any time in the for format XX:XX:XX and then ask for a time corrrection to add or subtract to this. my only problem is that once the user inputs the time and the correction its adding it like it was 100 not to 60 any help?
1
4338
by: treelife | last post by:
I'm getting and internal server error when | run the following mod_python script. I am actually trying to run Django. Script: from mod_python import apache def handler(req): req.content_type = 'text/plain' req.write("Under Construction")
16
2399
by: Durumdara | last post by:
Hi ! I have a problem. I have a little tool that can get data about filesystems and wrote it in python. The main user asked me a GUI for this software. This user is needed a portable program, so I create this kind of the software with Py2Exe.
25
2347
by: virg | last post by:
Hi, i have client-server application which is written in python using XMLRPC protocol. The existing client is a command line. Now client application we are converting it as Web UI using java. I have seen some problems in writing a java client. At the server for each request from client, the server sends a response in hashtable and is serialized using "pickle". The python function we call at the server is pickle.dumps(r, 2) -- where r...
2
234
by: ahmadoubay_20240 | last post by:
The assignment aims at enforcing the encryption and communication techniques. It helps the student in acquiring the necessary knowledge in developing client/server application and in securing data transfer using encryption techniques. Objectives can be summarized as: • Designing and implementing server applications • Designing and implementing client applications • Encrypting and decrypting o Use of DES, RSA o Use of hash...
0
2132
by: Ahmed, Shakir | last post by:
Thanks everyone who tried to help me to parse incoming email from an exchange server: Now, I am getting following error; I am not sure where I am doing wrong. I appreciate any help how to resolve this error and extract emails from an exchange server. First I tried: Traceback (most recent call last): File "<interactive input>", line 1, in ? File "C:\Python24\lib\poplib.py", line 96, in __init__ raise socket.error, msg
0
8249
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8179
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8633
jinu1996
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...
0
8493
tracyyun
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...
0
7176
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6112
isladogs
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...
0
5570
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();...
0
4084
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...
0
4187
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.