This encoding of the text before parsing worries me.  Can we not pass data.text directly to fromstring?  Can we use data.content?  Have we tested this on content in some challenging languages?