CGI python 3 write RAW BINARY

Antoine Pitrou solipsis at pitrou.net
Thu Apr 29 22:21:32 CEST 2010


Le Thu, 29 Apr 2010 18:33:08 +0200, Dodo a écrit :
> Oh, I tested on my windows machine avec sys.stdout.buffer.write() didn't
> work.
> I just tested on my linux server, and it works....
> 
> So, let's modify the script
> 
> 		sys.stdout.buffer.write( f.read() )
> 		sys.stdout.flush()

Sorry, I should have been clearer. You have to flush sys.stdout before 
using sys.stdout.buffer, such that the unicode layer doesn't keep any 
unwritten data. So this should be:

		sys.stdout.flush()
		sys.stdout.buffer.write( f.read() )

Regards

Antoine.




More information about the Python-list mailing list