Problem Displaying Pics

Victor Subervi victorsubervi at gmail.com
Wed Oct 7 19:50:00 CEST 2009


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

On Wed, Oct 7, 2009 at 12:00 PM, Rami Chowdhury <rami.chowdhury at gmail.com>wrote:

> On Wed, 07 Oct 2009 09:38:09 -0700, Victor Subervi <
> victorsubervi at gmail.com> wrote:
>
>  Yes it is. I have had it print to screen already, and there is data in the
>> database.
>> V
>>
>
> If you're confident that the data is correct and hasn't been corrupted,
> then I'm afraid I'm out of ideas. Perhaps you could try transmitting it as
> base64, which might make it more robust in transmission and easier to decode
> and find errors locally? You'd just need to change the end of your script to
> read:
>
> print '''Content-Type: image/jpeg
> Content-Encoding: base64
>
> '''
> print
> print content.encode('base64')
>
> HTH,
> Rami
>
>
>
>> On Wed, Oct 7, 2009 at 10:03 AM, Rami Chowdhury <rami.chowdhury at gmail.com
>> >wrote:
>>
>>  On Wed, 07 Oct 2009 06:37:08 -0700, Victor Subervi <
>>> victorsubervi at gmail.com> wrote:
>>>
>>>  I took out the line in question (with text/html). Now it prints to
>>> screen
>>>
>>>> the url. It did that before. Strange. Any other ideas?
>>>> TIA,
>>>> V
>>>>
>>>>
>>> Looking at the output, it seems the reason for this (for me) is that
>>> Firefox can't find the image or any alt text for it, so it's just using
>>> the
>>> image URL. Are you certain the image data (i.e. the 'content' string) is
>>> correct, and being encoded correctly in the output?
>>>
>>>
>>>
>>>  On Tue, Oct 6, 2009 at 3:40 PM, Rami Chowdhury <
>>>> rami.chowdhury at gmail.com
>>>> >wrote:
>>>>
>>>>  On Tue, 06 Oct 2009 13:26:19 -0700, Victor Subervi <
>>>>
>>>>> victorsubervi at gmail.com> wrote:
>>>>>
>>>>>  The code in question is generated automatically from another script. I
>>>>>
>>>>>  took
>>>>>> your idea of the \r\n\r\n and added triple quoting and now it prints
>>>>>> out
>>>>>> 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]
>>>>>> print '''Content-Type: text/html
>>>>>>
>>>>>> '''
>>>>>> 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
>>>>>>
>>>>>> '''
>>>>>> print
>>>>>> print content
>>>>>>
>>>>>>
>>>>>> To answer your questions, I have no idea what eNom has done to their
>>>>>> servers, which is where the other site was hosted (never went live),
>>>>>> but
>>>>>> am
>>>>>> in the process of building on DreamHost, who seems to be a FAR better
>>>>>> service than eNom, whom I actually had to report to the BBB and they
>>>>>> never
>>>>>> fixed or acknowledged very obvious problems. At any rate, the above
>>>>>> code
>>>>>> gets the browser to print out all the binary "garbage" that should
>>>>>> translate
>>>>>> into an image (you can look:
>>>>>> http://13gems.com/stxresort/cart/getpic1.py?id=1&x=1 ). Any more
>>>>>> ideas
>>>>>> would
>>>>>> be helpful.
>>>>>>
>>>>>>
>>>>>>  Going to that URL, my browser now tries to render an HTML page, and I
>>>>> can
>>>>> now see the 'Content-Type: image/jpeg' string being printed into the
>>>>> HTML
>>>>> source. Have you tried removing the 'Content-Type: text/html' header,
>>>>> with
>>>>> the new triple-quoted syntax?
>>>>>
>>>>>
>>>>> --
>>>>> 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)
>>>
>>>
>
>
> --
> 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)
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20091007/75c93c26/attachment.html>


More information about the Python-list mailing list