Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 9 Oct 2009 18:49:24 -0700 (PDT)
From:      Richard Mahlerwein <mahlerrd@yahoo.com>
To:        FreeBSD-Questions <freebsd-questions@freebsd.org>
Cc:        Victor Subervi <victorsubervi@gmail.com>
Subject:   Re: Automatic chmod
Message-ID:  <729381.76401.qm@web51012.mail.re2.yahoo.com>

next in thread | raw e-mail | index | archive | help
>From: Victor Subervi <victorsubervi@gmail.com>
>Subject: Re: Automatic chmod
>To: mahlerrd@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 =3D login()
>form =3D cgi.FieldStorage()
>picid =3D int(form['id'].value)
>x =3D int(form['x'].value)
>pics =3D {1:'pic1',2:'pic2',3:'pic3',4:'pic4',5:'pic5',6:'pic6'}
>pic =3D pics[x]
>db =3D MySQLdb.connect(host=3Dhost, user=3Duser, passwd=3Dpasswd, db=3Ddb)
>cursor=3D db.cursor()
>sql =3D "select " + pic + " from productsX where id=3D'" + str(picid) + "'=
;"
>cursor.execute(sql)
>content =3D 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.=A0 I'm no Python expert (in fact,=
 this was the first time I've touched it), but your code, with heavy modifi=
cations to slim it to something that can run on my system, seems to be most=
ly OK.=A0 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=3D"root"
passwd=3D""
db=3D"mysql"
host=3D"localhost"
form =3D cgi.FieldStorage()
db =3D MySQLdb.connect(host=3Dhost, user=3Duser, passwd=3Dpasswd, db=3Ddb)
cursor=3D db.cursor()
sql =3D "select User from user;"
cursor.execute(sql)
content =3D 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.=
=A0 Not that I know it's correct or what's needed, but it seems to print wh=
at you'd think it would.

Can you try running a test script that does, Oh, say, something like the be=
low to see if it works?=A0 (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.=A0 The above may pinpoi=
nt what sort of permissions issue it is.=A0 Besides, if it works, you could=
 slowly add in lines from your previous example until you find the offendin=
g line...=20

Also, If you haven't already done so, you may want to try posting in some p=
ython help forums or something.=A0 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.


=0A=0A=0A      



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?729381.76401.qm>