Buffered Stream and unicode

2 views
Skip to first unread message

akhen

unread,
Mar 15, 2010, 6:52:36 AM3/15/10
to Concurrence
Hi

I'm trying to write a chat server mostly based on the example from
documentation.

I need to write message in unicode, but get
File "build/bdist.macosx-10.4-i386/egg/concurrence/io/buffered.py",
line 117, in write_bytes
assert type(s) == str, "arg must be a str, got: %s" % type(s)
AssertionError: arg must be a str, got: <type 'unicode'>

def write_bytes(self, s):
assert type(s) == str, "arg must be a str"

Why does it only accepts str ?
What could be a workaround ?

Thanks for your help

Henk Punt

unread,
Mar 15, 2010, 3:37:52 PM3/15/10
to concurrenc...@googlegroups.com
this is because communication protocols at the socket level are 8-bit protocols.
You are trying to send a unicode string, which needs to be encoded in
some form before
it can be send over the wire. This is because unicode characters can
potentially be more than 1 byte in size.
Most common encoding is utf-8, be sure that on the receiving side you
'decode' using the same encoding.
i think unicode strings have a 'encode' method that you can call =
e.g. u'blaat'.encode('utf-8')

> --
> You received this message because you are subscribed to the Google Groups "Concurrence" group.
> To post to this group, send email to concurrenc...@googlegroups.com.
> To unsubscribe from this group, send email to concurrence-fram...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/concurrence-framework?hl=en.
>
>

akhen

unread,
Mar 15, 2010, 4:30:29 PM3/15/10
to Concurrence
Thanks Henk !
Reply all
Reply to author
Forward
0 new messages