![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Programming Guru
![]() Join Date: Apr 2005
Posts: 1,799
Rep Power: 5
![]() |
Re: Running python scripts on localhost
If hello world is displayed successfully, then everything is running fine. Your other scripts must not be consistent with the working script, or still contain errors.
Post the hello world script. Then post a simple script that you can't get working. |
|
|
|
|
|
#12 |
|
Newbie
Join Date: Jan 2008
Posts: 27
Rep Power: 0
![]() |
Re: Running python scripts on localhost
I have attached the form-sample.zip ( python script for making forms) which i am trying to use. But on running it, the browser shows the error page, with statement that there is some error in the cgi script.
The hello-world.py is simply : print "hello world" And that runs successfully. ![]() |
|
|
|
|
|
#13 |
|
Programming Guru
![]() Join Date: Apr 2005
Posts: 1,799
Rep Power: 5
![]() |
Re: Running python scripts on localhost
The zip file is corrupted.
But 45 kb? There are way too many reasons why such a large Python script won't work first shot. Either get a smaller Python script to work. Or build an understanding of Python so you can debug it correctly. Post it again within [code][/code] tags please if you don't mind more unhelpful replies. |
|
|
|
|
|
#14 |
|
Newbie
Join Date: Jan 2008
Posts: 27
Rep Power: 0
![]() |
No. the zip file is working. I tested it.
But I tried this also : class Eb_db: def __init__(self): try: connection = MySQLdb.connect(host="localhost", user="swan", passwd="swan", db="swan" ) cursor = connection.cursor() cursor.execute( "SELECT * FROM Table1 " ) except MySQLdb.OperationalError, message: errorMessage = "Error %d:\n%s" % (message[ 0 ], message[ 1 ] ) return else: self.data = cursor.fetchall() self.fields = cursor.description cursor.close() connection.close() ( From tutorial : http://www.serpia.org/blog/2007/oct/...-mysql-python/ ) But the code doesnot work. And most frustating is the fact that no error is generated. It just shows the same black and white page saying some error has occured in the cgi script. Where the error occured, What is the type of error, Why the error occured....Nothing. ![]() |
|
|
|
|
|
#15 |
|
Programming Guru
![]() Join Date: Apr 2005
Posts: 1,799
Rep Power: 5
![]() |
Re: Running python scripts on localhost
Firstly: Refer to my very first reply in this thread. Does your code begin with, and follow, that template?
Secondly: Does the code at least compile in your local Python interpreter? Thirdly: Please wrap your code in [code][/code] tags next time. Fourthly: Your code does not even have a single print statement. How do you expect it to make visible output? Do you even know how to program in Python?
__________________
Waterloo's Canadian Computing Competition (CCC) - Stage 2 Problems, Solutions, and Test Data Last edited by Sane; Feb 15th, 2008 at 3:42 PM. |
|
|
|
|
|
#16 | |
|
Newbie
Join Date: Jan 2008
Posts: 27
Rep Power: 0
![]() |
Re: Running python scripts on localhost
Quote:
Ok so according to you ,i should test this : #!c:/python24/python import cgitb import cgi cgitb.enable() print "Content-type: text/html\r" print "\r" class Eb_db: def __init__(self): try: connection = MySQLdb.connect(host="localhost", user="swan", passwd="swan", db="swan" ) cursor = connection.cursor() cursor.execute( "SELECT * FROM Table1 " ) except MySQLdb.OperationalError, message: errorMessage = "Error %d:\n%s" % (message[ 0 ], message[ 1 ] ) return else: self.data = cursor.fetchall() self.fields = cursor.description cursor.close() connection.close() I agree, i am new to python, but i know php, and can run the same program in php. Yah ! the code doesnot output anything, but atleast doesnot give any error when a similar program is made in php. |
|
|
|
|
|
|
#17 |
|
Programming Guru
![]() Join Date: Apr 2005
Posts: 1,799
Rep Power: 5
![]() |
Re: Running python scripts on localhost
In CGI-Land, not sending data back to the user is the equivilent of an error. What could appear to be an error is just a lack of you sending the appropriate header information at the top with:
print "Content-type: text/html\r" print "\r" Also, look at the "Hello World" script you said you were able to get working. It should have a line at the top that's similar or equal to my first line. Use the hello world's script first line instead of mine, because it knows the correct location of your Python interpreter. |
|
|
|
|
|
#18 | |
|
Newbie
Join Date: Jan 2008
Posts: 27
Rep Power: 0
![]() |
Re: Running python scripts on localhost
Quote:
. And the local python interpreter gives no error.An another working script is : print "Content-type: text/html\n\n" print "<html><head><link href=\"../styles.css\" rel=\"stylesheet\" type=\"text/css\"></head><body>" import os, sys print " <br><h1>Python %s</h1>" % sys.version print "</body></html>" It provides the output : Python 2.3.3 (#51, Dec 18 2003, 20:22:39) [MSC v.1200 32 bit (Intel)] |
|
|
|
|
|
|
#19 |
|
Programming Guru
![]() Join Date: Apr 2005
Posts: 1,799
Rep Power: 5
![]() |
Re: Running python scripts on localhost
Okay, so it looks like you don't need that first line. It should be obvious to try this as the start of your code then:
import cgitb import cgi cgitb.enable() print "Content-type: text/html\n\n" To replace what I proposed earlier: #!c:/python24/python import cgitb import cgi cgitb.enable() print "Content-type: text/html\r" print "\r" |
|
|
|
|
|
#20 | |
|
Newbie
Join Date: Jan 2008
Posts: 27
Rep Power: 0
![]() |
Re: Running python scripts on localhost
But you can see, i don't need these :
Quote:
|
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| understanding scripts | Special T | Delphi | 0 | Oct 24th, 2006 8:26 PM |
| How to run Python scripts in a browser window | titaniumdecoy | Python | 6 | Jun 30th, 2006 2:39 AM |
| [tutorial] Python for programming beginners | coldDeath | Python | 30 | Dec 14th, 2005 11:35 AM |
| Anyone ever see an assembly program that could run python scripts? | Datalisk | Python | 5 | Oct 23rd, 2005 10:37 AM |
| Python - A Programmers Introduction | coldDeath | Python | 17 | Aug 19th, 2005 12:41 PM |