python-wordpress-xmlrpc icon indicating copy to clipboard operation
python-wordpress-xmlrpc copied to clipboard

UnicodeDecodeError on printing comments with unicode in them

Open tankorsmash opened this issue 11 years ago • 2 comments

Whenever you retrieve or create a comment with valid unicode content, the __repr__ method fails on decoding. Seems like it's trying to convert what happens to be a unicode (or ASCII?) string encoded as string, then decoded to UTF. It's only an issue because when I try to print the returned list of Comments from a request, I get the error.

To reproduce:

new_comment =  WordPressComment({'content':"\xa0"})
print new_comment 
>>> *** UnicodeDecodeError: 'ascii' codec can't decode byte 0xa0 in position 0: ordinal not in range(128)

I think it's the equivalent of doing

print str(u'\xa0')
#or
unicode('\xa0')

But I'm not really familiar with this sort of thing so this could very well be a bad idea, but is it maybe worth trying to use unicode(self) instead of the str(self).encode('utf-8') ?

tankorsmash avatar Jun 16 '13 21:06 tankorsmash

I have the same problem when retriving posts with norwegian æøå in their titles. If i try to print, i get the same error as tankorsmash.

Cheers Bonsak

bonsak avatar Sep 06 '13 23:09 bonsak

Same happens here when trying to print GetPosts.

Lobosque avatar Apr 16 '15 00:04 Lobosque