Creating a CDATA block is not 100% reliable e.g. if the content is talking about how to use CDATA blocks, you will end up with nested CDATA blocks, which doesn't work Microsoft smart quotes will also break things. Post the failing bit of content and I'll see if I can spot the error.

When you're having problems like this, one trick you can use is to save the output to a file, then open it in a browser - it might give you more clues as to what the problem is. Also, if I open the XML up in Notepad++, the syntax highlighting tells me something is wrong.

Oops! You've right! I closed tag correctly and still can get right output. Problem is with putting UTF-8 to console. On test charset characters Awasu is talking about mistake... I'm looking for alternative to print to write output.

I get io.TextIOWrapper, you seem to have PseudoOutputFile, and given that the traceback points to a file called pyshell, I rather suspect it's ipython that's screwing things up (at a guess, I'd say it's capturing the output so it can do something with it).