#2039: torrentmanager.py line 1023, in on_alert_tracker_warning -
UnicodeDecodeError
---------------------+------------------------------------------------------
Reporter: non7top | Owner:
Type: bug | Status: new
Priority: minor | Milestone: 1.4.0
Component: core | Version: git master
Keywords: |
---------------------+------------------------------------------------------
Comment(by bro):
I logged the RPC message sent from the daemon with the torrent list, and
the dictionary entry looks like this (almost):
'tracker_status': 'site: Error: Message with bad character \xe5 in the
middle!',
The string is in fact latin1 (ISO-8859-1), so this works:
{{{
>>> s = 'String with \xe5'
>>> s = s.decode("ISO-8859-1")
>>> tracker_status = '%s: %s' % (u"Warning", s)
>>> tracker_status
u'Warning: String with \xe5'
}}}
What about first trying to decode for utf8, and if it fails, try
ISO-8859-1?
If both fail, use decode("utf8", "ignore").
Something like this:
{{{
#!/usr/bin/env python
import codecs
error_occured = False
def decode_string(s):
global error_occured
if type(s) is unicode:
return s
def error_handler(exc):
"""This also avoids pesky prints to terminal by decode when it
fails"""
global error_occured
error_occured = True
return (u"", exc.end)
codecs.register_error("decoding-error-handler", error_handler)
s2 = s.decode("utf8", "decoding-error-handler")
if not error_occured:
return s2
error_occured = False
s2 = s.decode("ISO-8859-1", "decoding-error-handler")
if not error_occured:
return s2
return s.decode("utf8", "ignore")
s1 = 'String with \xe5'
s2 = u'String with \xe5'
s3 = 'String with \xc3\xa5'
print "decode s1:", decode_string(s1)
print "decode s2:", decode_string(s2)
print "decode s3:", decode_string(s3)
}}}
Ouputs the following:
{{{
decode s1: String with å
decode s2: String with å
decode s3: String with å
}}}
--
Ticket URL: <http://dev.deluge-torrent.org/ticket/2039#comment:8>
Deluge <http://deluge-torrent.org/>
Deluge project
--
You received this message because you are subscribed to the Google Groups
"Deluge Dev" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/deluge-dev?hl=en.