When you put the 'wb' extension you have to pass a Encode the string Python does not accept a string on a wb file, Python3<br /><br />On Oct 6, 2010 1:01am, Chris Rebert <clp2@rebertia.com> wrote:<br />> > On Oct 5, 2010 8:03pm, MRAB python@mrabarnett.plus.com> wrote:<br />> <br />> >> On 05/10/2010 23:50, hidura@gmail.com wrote:<br />> <br />> >> I did but the mistake is: Error interpreting JPEG image file (Not a JPEG<br />> <br />> >> file: starts with 0x5c 0x6e)<br />> <br />> >><br />> <br />> >> I think the problem is maybe in the binary code here is:<br />> <br />> <br />> <br />> >>  > On Oct 5, 2010 6:18pm, "Jonas H." jonas@lophus.org> wrote:<br />> <br />> >>  > > On 10/05/2010 11:11 PM, hidura@gmail.com wrote:<br />> <br />> >>  > > Hello, how i can save a binary file, i read in the manual in the IO<br />> <br />> >> area<br />> <br />> >>  > > but doesn' t show how to save it.<br />> <br />> >><br />> <br />> >>  > > Here is the code what i am using:<br />> <br />> >>  > > s = open('/home/hidura/test.jpeg', 'wb')<br />> <br />> >>  > > s.write(str.encode(formFields[5]))<br />> <br />> >>  > > s.close()<br />> <br />> <br />> <br />> >> Why are you encoding it? A JPEG file should contain the binary data,<br />> <br />> >> not a textual encoding of its bytes. The error message you got said<br />> <br />> >> that the contents of the file started with a backslash.<br />> <br />> >><br />> <br />> >> If you print out, say, repr(str[ : 10]) you should get something like<br />> <br />> >><br />> <br />> >> '’Ų’ą\x00\x10JFIF'.<br />> <br />> >><br />> <br />> >> Try this instead:<br />> <br />> >><br />> <br />> >> s = open('/home/hidura/test.jpeg', 'wb')<br />> <br />> >> s.write(str)<br />> <br />> >> s.close()<br />> <br />> >><br />> <br />> >> Incidentally, 'str' is a bad name for a variable because it's the name<br />> <br />> >> of the built-in string type.<br />> <br />> <br />> <br />> On Tue, Oct 5, 2010 at 9:53 PM,  hidura@gmail.com> wrote:<br />> <br />> > I has to use repr to convert in this string: ’Ų’ą\x00\x10JFIF?<br />> <br />> <br />> <br />> No, you don't/shouldn't convert it at all. Read/use the 3 lines of<br />> <br />> suggested code that MRAB gave:<br />> <br />> s = open('/home/hidura/test.jpeg', 'wb')<br />> <br />> s.write(str)<br />> <br />> s.close()<br />> <br />> <br />> <br />> Cheers,<br />> <br />> Chris<br />>