[issue16456] UnicodeDecodeError thrown for 'encode' operation on string

Wojtek Szymilowski report at bugs.python.org
Sun Nov 11 23:51:36 CET 2012


New submission from Wojtek Szymilowski:

UnicodeDecodeError exception is reported for encode operation on strings.
This issue does not surface for the same operation on unicode string (UnicodeEncodeError exception is correctly reported).

---- string:
>>> 'AB\xff'.encode('ascii')

Traceback (most recent call last):
  File "<pyshell#27>", line 1, in <module>
    'AB\xff'.encode('ascii')
UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 2: ordinal not in range(128)

---- unicode string:
>>> u'AB\xff'.encode('ascii')

Traceback (most recent call last):
  File "<pyshell#28>", line 1, in <module>
    u'AB\xff'.encode('ascii')
UnicodeEncodeError: 'ascii' codec can't encode character u'\xff' in position 2: ordinal not in range(128)

----------
components: Unicode
messages: 175404
nosy: Wojtek.Szymilowski, ezio.melotti
priority: normal
severity: normal
status: open
title: UnicodeDecodeError thrown for 'encode' operation on string
type: behavior
versions: Python 2.7

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue16456>
_______________________________________


More information about the Python-bugs-list mailing list