>From: Victor Subervi <victorsube...@gmail.com>
>Subject: Re: Automatic chmod
>To: mahle...@yahoo.com, freebsd-questions@freebsd.org
>Date: Friday, October 9, 2009, 11:20 AM
>
>User? I only have one user on this shared server. Here's the code:
>
>#!/usr/local/bin/python
>import cgitb; cgitb.enable()
>import MySQLdb
>import cgi
>import sys,os
>sys.path.append(os.getcwd())
>from login import login
>user, passwd, db, host = login()
>form = cgi.FieldStorage()
>picid = int(form['id'].value)
>x = int(form['x'].value)
>pics = {1:'pic1',2:'pic2',3:'pic3',4:'pic4',5:'pic5',6:'pic6'}
>pic = pics[x]
>db = MySQLdb.connect(host=host, user=user, passwd=passwd, db=db)
>cursor= db.cursor()
>sql = "select " + pic + " from productsX where id='" + str(picid) + "';"
>cursor.execute(sql)
>content = cursor.fetchall()[0][0].tostring()
>cursor.close()
>print '''Content-Type: text/plain
>Content-Encoding: base64
>'''
>print
>print content.encode('base64')

I finally got to where I could test this.  I'm no Python expert (in fact, this 
was the first time I've touched it), but your code, with heavy modifications to 
slim it to something that can run on my system, seems to be mostly OK.  Here's 
the code I ended up with:
**********
#!/usr/local/bin/python
import cgitb; cgitb.enable()
import MySQLdb
import cgi
import sys,os
sys.path.append(os.getcwd())
user="root"
passwd=""
db="mysql"
host="localhost"
form = cgi.FieldStorage()
db = MySQLdb.connect(host=host, user=user, passwd=passwd, db=db)
cursor= db.cursor()
sql = "select User from user;"
cursor.execute(sql)
content = cursor.fetchall()
cursor.close()
print '''Content-Type: text/plain
Content-Encoding: base64
'''
print
print content
**********
That all seems to work as I would expect and gives not unreasonable output.  
Not that I know it's correct or what's needed, but it seems to print what you'd 
think it would.

Can you try running a test script that does, Oh, say, something like the below 
to see if it works?  (AGAIN, I don't know python AND I'm not testing this, just 
hand-writing it so excuse my code!)

#!/usr/local/bin/python
print '''Content-Type: text/plain
'''
print "Hopefully this works"

At this point, I really haven't much more to go on.  The above may pinpoint 
what sort of permissions issue it is.  Besides, if it works, you could slowly 
add in lines from your previous example until you find the offending line... 

Also, If you haven't already done so, you may want to try posting in some 
python help forums or something.  This doesn't have the feel of a FreeBSD 
specific problem, so there's bound to be other Python folks who've hit this and 
solved it before.






_______________________________________________
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"

Reply via email to