Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jan 31st, 2008, 12:31 PM   #11
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,835
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
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.
Sane is offline   Reply With Quote
Old Feb 2nd, 2008, 12:31 AM   #12
Swan
Programmer
 
Join Date: Jan 2008
Posts: 31
Rep Power: 0 Swan is on a distinguished road
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.
Attached Files
File Type: zip form-sample.zip (44.0 KB, 2 views)
Swan is offline   Reply With Quote
Old Feb 2nd, 2008, 8:09 AM   #13
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,835
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
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.
Sane is offline   Reply With Quote
Old Feb 14th, 2008, 11:25 PM   #14
Swan
Programmer
 
Join Date: Jan 2008
Posts: 31
Rep Power: 0 Swan is on a distinguished road
Unhappy Re: Running python scripts on localhost

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.
Swan is offline   Reply With Quote
Old Feb 15th, 2008, 3:29 PM   #15
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,835
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
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?

Last edited by Sane; Feb 15th, 2008 at 3:42 PM.
Sane is offline   Reply With Quote
Old Feb 16th, 2008, 12:19 AM   #16
Swan
Programmer
 
Join Date: Jan 2008
Posts: 31
Rep Power: 0 Swan is on a distinguished road
Re: Running python scripts on localhost

Quote:
Originally Posted by Sane View Post
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?

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.
Swan is offline   Reply With Quote
Old Feb 16th, 2008, 9:17 AM   #17
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,835
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
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.
Sane is offline   Reply With Quote
Old Feb 17th, 2008, 9:11 PM   #18
Swan
Programmer
 
Join Date: Jan 2008
Posts: 31
Rep Power: 0 Swan is on a distinguished road
Re: Running python scripts on localhost

Quote:
Originally Posted by Sane View Post
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.
No...! it doesnot work . 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 "&nbsp;<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)]
Swan is offline   Reply With Quote
Old Feb 17th, 2008, 10:06 PM   #19
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,835
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
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"
Sane is offline   Reply With Quote
Old Feb 18th, 2008, 10:18 PM   #20
Swan
Programmer
 
Join Date: Jan 2008
Posts: 31
Rep Power: 0 Swan is on a distinguished road
Re: Running python scripts on localhost

But you can see, i don't need these :
Quote:
import cgitb
import cgi
cgitb.enable()
So why write them ?
Swan is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:01 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC