Problem Displaying Pics

Rami Chowdhury rami.chowdhury at gmail.com
Wed Oct 7 20:52:42 CEST 2009


On Wed, 07 Oct 2009 11:51:13 -0700, Victor Subervi  
<victorsubervi at gmail.com> wrote:

> My misunderstanding. Here's the new code:
>
> print '''Content-Type: image/jpeg
>
>
> Content-Encoding: base64
> '''

Ah, sorry, I wasn't clear -- Content-Encoding is a header, and needs to go  
with Content-Type, before the newlines. So

print '''Content-Type: image/jpeg
Content-Encoding: base64

'''

HTH,
Rami


>
>
> On Wed, Oct 7, 2009 at 12:56 PM, Rami Chowdhury  
> <rami.chowdhury at gmail.com>wrote:
>
>> On Wed, 07 Oct 2009 10:50:00 -0700, Victor Subervi <
>> victorsubervi at 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)
>>



-- 
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)



More information about the Python-list mailing list