Search code examples
pythonqstringpython-unicode

Python encoding error when trying to print a QString


I try to print a PyQt4.QtCore.QString object:

print str(type(html))
print str(html)

However, I get the following error:

<class 'PyQt4.QtCore.QString'>
Traceback (most recent call last):
  File "download.py", line 23, in <module>
    print str(html)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2039' in position 4165: ordinal not in range(128)

What is going wrong here?


Solution

  • It is possible with

    print unicode(html)