On Wed, 19 Oct 2005 09:51:32 +1000, Kinsley Turner 
<[EMAIL PROTECTED]> wrote:

>Hey-ho,
>
>I'm having a problem with some binary data read into a string.
>
>Basically I open an icon file "rb", read() it into a string, then
>spit it back down on a web request for /favicon.ico.
>
>It works fine under unix, but under Win32 Python 2.4.2 (#67, Sep 28 2005 
>...
>It comes back corrupted.
>
>Similiarly I have a string with the IBM-extended-ASCII degrees symbol 
>(ascii 0xb0) 
>that is read in from a network-connected field device.  Somehow this ends 
>up with 
>an extended 'A' (with a single dot over it.) prepended before it.
>
>Is there some sort of new 2.4 string encoding option I've missed ?
>Never seen anything like this before.
>
>I have the "# -*- coding: iso-8859-1 -*-" atop my files.
>


Are you writing this as a CGI process in Apache/Win32?  Have you 
redefined your stdout to be binary?  By default, Python opens its stdout 
as binary, so when you write this out to the socket, the file system 
will "helpfully" translate 0A to 0D/0A.  You need something like this:

    import msvcrt
    msvcrt.setmode( 0, os.O_BINARY )
    msvcrt.setmode( 1, os.O_BINARY )

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

_______________________________________________
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to