[Twisted-Python] Twisted Web, Unicode & request.write()
Hi Y'all, What's the correct way to write out Unicode data to the client in Twisted Web? request.write() throws a "Data must not be unicode". Content-Type header is set with "; charset=utf-8" appended to the content type. -J
On Wed, Jun 16, 2010 at 12:50 AM, Jason J. W. Williams
Hi Y'all,
What's the correct way to write out Unicode data to the client in Twisted Web? request.write() throws a "Data must not be unicode". Content-Type header is set with "; charset=utf-8" appended to the content type.
Encode it to bytes with ustr.encode("utf-8") and then pass it to request.write. -- Christopher Armstrong http://radix.twistedmatrix.com/ http://planet-if.com/
On 2010-06-15, Jason J. W. Williams wrote:
Hi Y'all,
What's the correct way to write out Unicode data to the client in Twisted Web? request.write() throws a "Data must not be unicode". Content-Type header is set with "; charset=utf-8" appended to the content type.
If you say the charset utf-8, you should emit utf-8. u'foo'.encode('utf-8') converts from a python unicode object to a str encoded using the utf-8 codec. -- Regards, Stephen Thorne Development Engineer Netbox Blue
Thanks guys. I actually backed into that myself in the last hour. Was
just about to write back with the discovered correction. Makes sense.
-J
On Wed, Jun 16, 2010 at 12:16 AM, Stephen Thorne
On 2010-06-15, Jason J. W. Williams wrote:
Hi Y'all,
What's the correct way to write out Unicode data to the client in Twisted Web? request.write() throws a "Data must not be unicode". Content-Type header is set with "; charset=utf-8" appended to the content type.
If you say the charset utf-8, you should emit utf-8.
u'foo'.encode('utf-8') converts from a python unicode object to a str encoded using the utf-8 codec.
-- Regards, Stephen Thorne Development Engineer Netbox Blue
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
participants (3)
-
Christopher Armstrong
-
Jason J. W. Williams
-
Stephen Thorne