On Wed, Apr 9, 2008 at 11:10 AM, Steve Holden <[EMAIL PROTECTED]> wrote:
> Victor Subervi wrote: > > > On Wed, Apr 9, 2008 at 10:24 AM, Steve Holden <[EMAIL PROTECTED]<mailto: > > [EMAIL PROTECTED]>> wrote: > > connection = MySQLdb.connect(host=host, user=user, passwd=passwd, db=db) > > cursor = connection.cursor() > > cursor.execute('select img from photo where id="7";') > > content = cursor.fetchall() > > > > Bzzt! Nope. Cursor.fetchall() returns a list (length 1) or tuples (length > 1) here, so this should be > > content = cursor.fetchall()[0][0] > > or, perhaps better > > content = cursor.fetchone()[0] I tried both of these, and they, too, gave me the same identical image of the url, not the image I am after. > > > You really don't understand how the web works, do you? I am just really, really, stupid, Steve. Please forgive me for being so stupid. But I am persistent. And I have built dozens of Web site with images. > In order to include an image in a page your browser must make TWO > requests. The first is for an HTML page that will reference the image in > this way: > > <img src="http://your URL here"> > > Seeing this img tag causes the browser to make a SECOND request, which the > script I corrected above should respond to with an image. > > The bytestream is critical in the image response. Even one misplaced byte > will mess things up terribly. In my stupidity, I have assumed you meant this: content = col_fields[0][14].tostring() print '<img src="', content, '"><br /><br />' Obviously I am wrong. Could you please give me a little more insight? > BTW, when we are finally done with this, I will write a nice how-to (since > > there is not one in python, while php has some nice ones) on how to do this, > > and give you and Gabrielle all your due credit. I will post it to this list, > > because that is sure to rank highly in google right away. > > Victor > > > > That's great, though hardly the point of the exercise. I think Google > already know about Gabriel (*not* Gabrielle) and me already ... Well, I just thought it might be a good way to get the information out, since it is not out there yet. And I believe it is only proper to give credit where credit is due. I would not be doing this to praise you. Rather, I would be doing this because it is needed, and I would feel wrong for not crediting those who deserve credit. Please let me know, however, if you feel otherwise. TIA, Victor
-- http://mail.python.org/mailman/listinfo/python-list