Problem Displaying Pics

Rami Chowdhury rami.chowdhury at gmail.com
Tue Oct 6 16:40:56 EDT 2009


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)



More information about the Python-list mailing list