More Fun With MySQL and Images

J. Cliff Dyer jcd at unc.edu
Thu Apr 17 11:39:53 EDT 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
out.

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.

Cheers,
Cliff




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




More information about the Python-list mailing list