[pygtk] assertion g_utf8_validate failed when I set text to textview
Tony Nelson
tonynelson at georgeanelson.com
Thu Jul 16 23:12:00 WST 2009
On 09-07-16 08:48:25, nohics nohics wrote:
> But how can we know what's all the invalid UTF-8 characters (like
> \x00) ?
He's suggesting that instead of passing unclean data, that you convert
it to Unicode yourself, possibly removing some expected bad characters
yourself (a NUL might well terminate the string in GTK's C-based view
of things). For example, from the Python command line:
>>> '\200'.decode('utf-8', 'replace')
u'\ufffd'
>>> '\200'.decode('utf-8', 'ignore')
u''
>>> '\200'.decode('utf-8', 'strict')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.5/encodings/utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0x80 in position 0:
unexpected code byte
> 2009/7/15 saeed <saeed.gnu at gmail.com>
>
> > Maybe the string has invalid UTF-8 characters. You may check and
> > correct it maulally, for example:
> > data = data.replace('\x00', '').decode('utf-8',
> > 'replace').encode('utf-8')
> >
> > On 7/15/09, nohics nohics <nohics at gmail.com> wrote:
> > > Hello all, I'm getting this error when I set a text on the
> > > textview (the text that I receive from an irc server when I
> > > connect to it): GtkWarning: gtk_text_buffer_emit_insert:
> > > assertion `g_utf8_validate(text, len, NULL)' failed
> > > textviewBuffer.insert(textviewBuffer.get_end_iter(), data)
> > >
> > > What's the problem ?
> > > Thank you.
--
____________________________________________________________________
TonyN.:' <mailto:tonynelson at georgeanelson.com>
' <http://www.georgeanelson.com/>
More information about the pygtk
mailing list