Upload of binary files

ben.hutchings at businesswebsoftware.com ben.hutchings at businesswebsoftware.com
Thu Mar 13 10:25:44 EST 2003


stdin and stdout are opened in text mode, since they are normally used
for text.  On Windows you need to switch them to binary mode if you
will read or write binary data.  I think you need to switch stdin
over before 'import cgi' as that may parse input immediately.  The
following code should do the trick:

try:
    import msvcrt, os
    msvcrt.setmode(0, os.O_BINARY) # stdin = 0
    msvcrt.setmode(1, os.O_BINARY) # stdout = 1
except ImportError:
    pass




More information about the Python-list mailing list