[Twisted-Python] Unicode

Andrew Bennetts andrew-twisted at puzzling.org
Mon Oct 3 22:58:28 EDT 2005

On Mon, Oct 03, 2005 at 06:19:44PM -0600, Ken Kinder wrote:
> The purpose of Python's unicode type is transparent exchange of string
> objects, whether those string objects are of type str or type unicode.
> Pretending that isn't so and raising a TypeError is not helpful. I would
> urge you to AT LEAST provide a detailed explanation in that error,
> explaining the philosophical disagreement you have with Python's
> unicode-string conversion behavior and have a flag you can set to
> disable that check.

The issue is that the python-global default implicit encoding of unicode to
str could be completely wrong for any given protocol and transport instance
(i.e. socket).  Protocol implementations should not be vulnerable to bugs
just because someone adds sys.setdefaultencoding('utf-16') to their

It's not hard at all to imagine a situation where two different sockets have
two completely different encodings -- e.g. HTTP servers can and should
choose charsets for responses based on what the client request asks for,

This is formally addressed in the Twisted documentation -- as a FAQ -- here:



More information about the Twisted-Python mailing list