Thank you Yejun.
I have now realized that the problem was that I was mixing strings and
binary bytes in the response. I started with a string header, which
must have initialized the StringIO to ASCII encoding. If I remove that
header, I don't have any errors. I'll change the string header to the
HTTP headers section, so I do not have to mess with mixing strings and
binary data.
On Oct 31, 7:53 pm, yejun <[EMAIL PROTECTED]> wrote:
> I tried your code. No error whatsoever and working as expected.
>
> On Oct 31, 12:33 pm, Sito <[EMAIL PROTECTED]> wrote:
>
> > Hi all,
>
> > I can't find a way to write arbitrary binary data in my response. I
> > have a big list of ints that I would like to serve in a response as
> > compact as possible. For this, I create an array of shorts (my ints
> > never take more than two bytes). I create my array like this:
>
> > from array import array
>
> > int_bytes = array('H')
> > for p in int_data:
> > int_bytes.append(p)
>
> > later on, when I want to write the response, I do this:
>
> > self.response.out.write(int_bytes.tostring())
>
> > but I get this nasty error:
>
> > UnicodeDecodeError: 'ascii' codec can't decode byte 0xf1 in position
> > 0: ordinal not in range(128)
>
> > I understand from this that StringIO, of which self.response.out is an
> > instance, does not accept bytes that cannot be encoded to ascii.
>
> > Does anyone know how I can do to write this kind of binary data?
>
> > Thank you,
>
> > Alfonso
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---