My misunderstanding. Here's the new 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 products where id='" + str(picid) + "';" cursor.execute(sql) content = cursor.fetchall()[0][0].tostring() cursor.close() print '''Content-Type: image/jpeg
Content-Encoding: base64 ''' print print content.encode('base64') Unfortunately, the same result of printing the url. V On Wed, Oct 7, 2009 at 12:56 PM, Rami Chowdhury <rami.chowdh...@gmail.com>wrote: > On Wed, 07 Oct 2009 10:50:00 -0700, Victor Subervi < > victorsube...@gmail.com> wrote: > > Well, since the code is automatically generated, it printed this: >> >> #!/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 products where id='" + str(picid) + "';" >> cursor.execute(sql) >> content = cursor.fetchall()[0][0].tostring() >> cursor.close() >> print '''Content-Type: image/jpeg >> >> ''' >> Content-Encoding: base64 >> print >> print content.encode('base64') >> >> which threw this error: >> >> [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler >> mod_python.cgihandler: Traceback (most recent call last): >> [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler >> mod_python.cgihandler: File >> "/usr/lib64/python2.4/site-packages/mod_python/apache.py", line 299, in >> HandlerDispatch\n result = object(req) >> [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler >> mod_python.cgihandler: File >> "/usr/lib64/python2.4/site-packages/mod_python/cgihandler.py", line 96, in >> handler\n imp.load_module(module_name, fd, path, desc) >> [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler >> mod_python.cgihandler: File "/var/www/vhosts/ >> 13gems.com/httpdocs/stxresort/cart/getpic1.py", line 24 >> [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler >> mod_python.cgihandler: Content-Encoding: base64 >> [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler >> mod_python.cgihandler: ^ >> [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler >> mod_python.cgihandler: SyntaxError: invalid syntax >> >> Ideas? TIA, >> V >> >> > I'm sorry, I don't understand how the code is being auto-generated? Is > there no way to place the 'Content-Encoding' header inside the triple-quoted > string, where it should go? > > -- > Rami Chowdhury > "Never attribute to malice that which can be attributed to stupidity" -- > Hanlon's Razor > 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) >
-- http://mail.python.org/mailman/listinfo/python-list