cgi and mime type

Michal Wallace sabren at manifestation.com
Tue Feb 12 17:46:57 EST 2002


On 12 Feb 2002, Chris Liechti wrote:

> aseem at neurobs.com (A M) wrote in news:ed6d1c1a.0202121225.295ca950
> @posting.google.com:
> 
> > fp = open('fp.exe')
> > print fp.read();
> 
> use open(name, 'rb') here. binary mode is important when the cgi runs 
> on win32. not sure if this fixes your other problem though...


I missed the start of this thread, but this might help
someone: when printing binary files on stdout on win32, you
also have to make stdout binary:

    if sys.platform=="win32":
        import msvcrt
        msvcrt.setmode(sys.__stdin__.fileno(), os.O_BINARY)
        msvcrt.setmode(sys.__stdout__.fileno(), os.O_BINARY)

And you'd probably also want to say:

sys.stdout.write(fp.read())

instead of "print" in the code above...

Cheers,

- Michal   http://www.sabren.net/   sabren at manifestation.com 
------------------------------------------------------------
Give your ideas the perfect home: http://www.cornerhost.com/
 cvs - weblogs - php - linux shell - perl/python/cgi - java
------------------------------------------------------------





More information about the Python-list mailing list