[Twisted-Python] response with special characters, utf-8
Mario Ruggier
mario at ruggier.org
Fri Mar 28 10:00:46 EST 2003
Hello,
the rpy below returns a string with special characters, which I
would like to be displayed by the web client. However the 3 non-ascii
characters below are displayed as garbage (even if differently), in two
browsers I have tried with (IE and Safari). What am I missing?
Thanks for any help,
mario
##################################
### chars_test.rpy
from twisted.web import resource
from twisted.web.server import NOT_DONE_YET
def errBack(err, request):
request.write('error: ' + str(err) )
request.finish()
def returnString(result, request):
request.setHeader = ('Content-Type', 'text/html; charset=utf-8')
request.write(result)
request.finish()
def responseString(request):
return '''<html><title>characters test</title>
</head>
<body>
3 sample èçé characters (e+grave, c+cedille, e+aigu)
</body>
</html>
'''
class MyResource(resource.Resource):
def render(self, request):
from twisted.internet import threads
d = threads.deferToThread(responseString,request)
d.addCallback(returnString,request)
d.addErrback(errBack, request)
return NOT_DONE_YET
###
resource = MyResource()
###
More information about the Twisted-Python
mailing list