The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
piping from C to python in UNIX Dreams in Blue High Level Programming 0 05-04-2008 08:02 AM
Html web page to Unix Connectivity abhilashnair UNIX and Linux Applications 1 03-06-2008 10:13 AM
Unix Shell Script along with .HTML ronix007 UNIX for Dummies Questions & Answers 3 01-07-2008 09:15 AM
How do I extract text only from html file without HTML tag los111 UNIX for Dummies Questions & Answers 4 11-28-2007 04:40 AM
HTML-CGI on Unix sstevens UNIX for Dummies Questions & Answers 4 12-03-2002 09:41 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-15-2007
davidfrank davidfrank is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 10
Python, HTML, and Unix

Hi Experts,

This may be the wrong category for posting my question, or it could be the perfect category to post. I have no idea how difficult my problem is.

I have python 2.3 installed in my server machine. I am trying to create a web page with python script in it. Now this can be a .html page with python embedded in it, or it could be a .py page with html embedded in it. Whatever it is, it's okay. I cannot use python templates like Kid, Spyce, etc., because my System Admin will not install new software into the machine (it's a 64 bit, cluster server, and he is very possessive about it). I have the CentOS operating system (a version of Red Hat Linux Enterprise). I followed the simple instructions given online, and created a page called trial.py with the following code in it:

#!/usr/bin/python
print "Content-type: text/html\n\n"
print "Hello World!!! <br />"
print "this is on the next line because of the line break above"

saved it into the public_html folder, and did $chmod 777 trial.py. Now, when I access this page from the browser (firefox) I get the display on the page to be the exact same code that I had written. That is, the page shows me:

#!/usr/bin/python
print "Content-type: text/html\n\n"
print "Hello World!!! <br />"
print "this is on the next line because of the line break above"

Now, the path to python, is /usr/bin/python. I have verified this with $which python, and I also have some python programs running with crontab that use this path, /usr/bin/python. I changed the file name to trial.cgi, did $chmod 777 trial.cgi, and use firefox to go to it, and I get a 403 Forbidden message saying "You don't have permission to access /~davidfrank/trial.cgi on this server".

So, I tried the other way around. I created a page called new.html, and once again followed the instructions in another online place and wrote the code as:

<html>
<body>
<script language="python2.3">
<!--
print "hello world!"
import string, re
-->
</script>
</body>
</html>

I again saved this into the public_html folder and did $chmod 777 new.html. Now when I access this page from the web browser (firefox), I get nothing on the display. The page is blank.

Please please do help me out. What am I doing wrong?! Is there a tutorial on this. Once again, I cannot use a framework like Kid or Spyce. I have to use the coding that is similar to other scripting languages.

I do not know if the server has Apache or CGI. I am guessing that my server uses Apache since several of the associated web addresses that have the same owners and name servers do use apache. So, now I create this .htaccess file (chmod 777) with the content as:

Options +ExecCGI
AddHandler cgi-script .py

and store it in the public_html folder (this has all the web page files for my username), but no effect. So, I try out the following content:

Options +ExecCGI
AddHandler cgi-script cgi pl

but still no effect. Then finally, I try out:

Options +ExecCGI
AddHandler cgi-script

and no effect after that too. I am at a complete loss now. If someone could please tell me what I am doing wrong or what I should do to get this working, I would truly appreciate it!

Thank you for your time and effort.
  #2 (permalink)  
Old 05-16-2007
craigp84 craigp84 is offline
Registered User
  
 

Join Date: May 2007
Location: Glasgow, Scotland
Posts: 59
Yes, 'tis easy

Hi Davidfrank,

Yes this is an easy one, but you were along the right lines at the end of the post anyway - you were almost there!

You're going to have to speak to your sysadmin to make a one line change in his httpd.conf for this apache instance.

Basically there's a line says "AllowOverride None" - get him to delete that and do a reload of apache, then your .htaccess should take effect, the important bits in there is the +ExecCGI and the AddHandler cgi-script .py - this ensures that any .py files in the current directory will be run through whatever's specified on the shebang line (#! at the top).

For this to work, you'll go with your first approach, creating trial.py and putting your python code in there. The second approach (create a .html with some script tags in) won't work here.

Hope this helps,

Craig
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:26 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0