Python, HTML, and Unix


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Python, HTML, and Unix
# 1  
Old 05-15-2007
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  
Old 05-16-2007
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How is html code read, compared to say python?

so, the first line of bash, perl, python, ruby, and similar languages must contain the path to the interpreter...i.e. #!/bin/perl, or #!/bin/python. so in the case of a perl script, for instance, a perl script cannot and will never run if the perl program is not installed/present on the system. ... (9 Replies)
Discussion started by: SkySmart
9 Replies

2. Shell Programming and Scripting

Not getting colorcode when excuting html in UNIX

Hi i have below code which i am running and the out i want should be in red color echo "<html>" >> ERROR_FILE.html echo "<Body>" >> ERROR_FILE.html nawk 'BEGIN{print "<table border="1">"} {print "<tr>"; print "<TD colspan="0" bgcolor="#DC143C">"; for(i=1;i<NF;i++)... (5 Replies)
Discussion started by: mirwasim
5 Replies

3. UNIX for Advanced & Expert Users

How to use HTML in UNIX Bash Scripting?

I am planning to run an automation , Could anyone try to help me to how to write an html in unix scripting so when I try to send email it should work especially with Bold and colors (6 Replies)
Discussion started by: cassia
6 Replies

4. Shell Programming and Scripting

HTML mail formating in UNIX

Hi i need to send mail from my Unix server i used the below code. From: TTS.OO.Monitoring.Operations Subject: Error X-Mailer: htmlmail 1.0 Mime-Version: 1.0 Content-Type: text/html; charset=US-ASCII <HTML><head><style type='text/css'> table.altrowstable { font-family:... (6 Replies)
Discussion started by: mohanalakshmi
6 Replies

5. UNIX for Advanced & Expert Users

Help to get file from windows to Unix via HTML

Dear, I have a requirement as below: I need an exe or bat file to facilitate multiple end users to upload their files (csv or xls) from windows environment to Unix server. Any front end like html would also be fine, I can develop a simple HTML script with browse button but not sure on... (4 Replies)
Discussion started by: Imran_Chennai
4 Replies

6. UNIX for Advanced & Expert Users

html parsing using unix

hi all, I had raised the same question a few weeks back but forgot to mention a lot of points ... so i am raising a new thread furnishing my requirement ... sorry for that .... here is my problem. i have a html that look like below <tr class="modifications-oddrow"> <td... (2 Replies)
Discussion started by: sais
2 Replies

7. Web Development

Login page in html on unix

I want to create a login page in HTML which is hosted on apache server. The login page first authenticate the user and then directed to a form which in turn run a script on the server. I want to make login page without php or jsp. Please advice. (13 Replies)
Discussion started by: ravi18s
13 Replies

8. Shell Programming and Scripting

Python in UNIX

Hi, I am going to handle a project that uses Python on AIX or SunSolaris Plateform. Please tell me what is Python and how and why we should use Python. Please suggest. Thanx. (2 Replies)
Discussion started by: sanjay1979
2 Replies

9. Programming

piping from C to python in UNIX

Hi, I'm trying to wrap my head around piping in C - I've got a small C program that forks and pipes stuff from the child process to the parent process. Currently the child process calls a C program that squirts out random numbers which then pipes the result to the parent process. The... (0 Replies)
Discussion started by: Dreams in Blue
0 Replies

10. UNIX for Dummies Questions & Answers

HTML-CGI on Unix

AAAHHH!! I've made a perl program that you can run on a web browser. This program needs to be run everyday, and I don't want to have to run it everyday. The problem is when I try running the program from my terminal, all it does is print stuff to the terminal page (the program involves a lot of... (4 Replies)
Discussion started by: sstevens
4 Replies
Login or Register to Ask a Question