More Fun With MySQL and Images

J. Cliff Dyer jcd at
Thu Apr 17 17:39:53 CEST 2008

On Thu, 2008-04-17 at 09:52 -0500, Victor Subervi wrote:
> Never mind. Apparently, these tags throw it for that loop:
>   print '<html><body>\n'
> I´m surprised they would, but gratified I found the problem.
> Victor

Why does that surprise you?  A jpeg has a well-defined header that tells
whatever application is rendering it what to look for.  By putting those
tags at the beginning of the data sent to your browser, you're no longer
getting a well-formed jpeg.  The header is wrong.  

As an experiment, if you're on *nix, or have access to a decent shell,
try this:

$ echo '<html><body>' > newfile.jpg
$ cat /path/to/any_normal_jpeg >> newfile.jpg
$ echo '</body></html>' >> newfile.jpg

If you don't have access to a shell, open a JPEG with your favorite text
editor, and manually add "<html><body>" to the beginning, and save it

Then try to open newfile in any piece of software of your choosing.
It's no longer a well-formed jpeg, so it won't work.  That's exactly
what you're asking the browser to do.

I guess this isn't really python related, so my apologies for that.


J. Cliff Dyer
Carolina Digital Library and Archives
UNC Chapel Hill

More information about the Python-list mailing list