Problem Displaying Pics

Victor Subervi victorsubervi at gmail.com
Tue Oct 6 16:26:19 EDT 2009


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.
TIA,
V

On Tue, Oct 6, 2009 at 2:48 PM, Rami Chowdhury <rami.chowdhury at gmail.com>wrote:

> On Tue, 06 Oct 2009 12:37:17 -0700, Victor Subervi <
> victorsubervi at gmail.com> wrote:
>
>  I remember going round and round on this issue before until I finally got
>> it
>> right. I haven't changed the code. It worked before. I just tried your
>> update and it gave me the same result :( Any other ideas?
>> TIA,
>> V
>>
>>
> I'm afraid changing the 'Content-type' header to be correct (which it's
> still not, by the way; you need to be printing '\r\n\r\n' after the
> content-type, to signal the end of the headers) is all I can think of. Apart
> from that, could it be a browser issue? When I went to the URL you provided
> in your first email, for instance, my browser (Opera 9.6 on Windows Vista)
> was expecting an image, as was Firefox 3.1 (again on Windows). However,
> neither seem to read valid data for the image, and both report it as 0x0.
>
> Could you give us more information on what has changed? Have you upgraded
> the version of Python on the server? Have you changed the webserver serving
> your scripts? Have you changed the back-end database at all?
>
>
>
>
> --
> 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/20091006/551f5f40/attachment.html>


More information about the Python-list mailing list