current email package' requirement to decode this to str for parsing is utterly incompatiblethough the cgi module' own code seems suspect for some cases as well if you want to see for yourself how data is actually uploaded by browserssee and run the html and python files named test-cgiu-uploads-bugin the examples package to upload textbinaryand mixed type filestest-cgi-uploads-bug html/py attempts to parse normallywhich works for some text files but always fails for binary files with unicode decoding error test-cgi-uploads-bug html/py tries binary mode for the input streambut always fails with type errors for both text and binary because of email' str requirement test-cgi-uploads-bug html/py saves the input stream for single file test-cgi-uploads-bug html/py saves the input stream for multiple files the last two of these scripts simply read the data in binary mode and save it in binary mode to file for inspectionand display two headers passed in environment variables which are used for parsing ( "multipart/form-datacontent type and boundaryalong with content lengthtrying to parse the saved input data with the cgi module fails unless the data is entirely text that is compatible with that module' encoding assumptions reallybecause the data can mix text and raw binary arbitrarilya correct parser will need to read it as bytes and switch between text and binary processing freely it seems likely that this will be improved in the futurebut perhaps not until python or later nearly two years after ' releasethoughthis book project has found itself playing the role of beta tester more often than it probably should this primarily derives from the fact that implications of the python str/bytes dichotomy were not fully resolved in python' own libraries prior to release this isn' meant to disparage people who have contributed much time and effort to alreadyof course as someone who remembers xthoughthis situation seems less than ideal writing replacement for the cgi module and the email package code it uses--the only true viable workaround--is not practical given this book project' constraints for nowthe cgi scripts that perform file uploads in this book will only work with text filesand then only with text files of compatible encodings this extends to email attachments uploaded to the pymailcgi webmail case study of the next -yet another reason why that example was not expanded with new functionality in this edition as much as the preceding pymailgui being unable to attach images to emails this way is severe functional limitationwhich limits scope in general for updates on the probable fix for this issue in the futurewatch this book' website (described in the prefacea fix seems likely to be incompatible with current library module apisbut short of writing every new system from scratchsuch is reality in the real world of software development (and no"running away moreis not an option server-side scripting