A UnicodeDecodeError exception is raised if a string is converted to a unicode object, but the default encoding (or an explicit encoding used) does not have support for mapping one of the characters in the string to a unicode ordinal. For example:

    >>>
    >>> title = "Hello á"
    >>> u = unicode(title)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    UnicodeDecodeError: 'ascii' codec can't decode byte 0xe1 in position 6: ordinal not in range(128)
    >>>
    >>> u = unicode(title, "latin1")
    >>> u
    u'Hello \xe1'
    >>>
    >>> u = title.decode("latin1")
    >>> print u
    Hello á
    >>> type(u)
    <type 'unicode'>
    >>>

UnicodeDecodeError (last edited 2008-03-11 10:50:23 by localhost)

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.