You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Trying to encode a character which is not supported by a codec will raise an exception (=> good). However, the error message is a bit misleading in some cases.
Example:
'ä'.encode('datamatrix.EDIFACT')
UnicodeEncodeError: 'ascii' codec can't encode character '\xe4' in position 0: ordinal not in range(128)
---------------------------------------------------------------------------
UnicodeEncodeError Traceback (most recent call last)
/InteractiveInput-1 in <module>
----> 1 'ä'.encode('datamatrix.EDIFACT')
~/Projects/ppf.datamatrix/src/ppf/datamatrix/codec_edifact.py in encode_to_edifact(msg)
46 elif n_rest == 1:
47 if len(msg) < 2:
---> 48 enc = (b'\xF0' + pack(msg.encode('ascii'), b'\x1F\x00\x00'))
49 else:
50 enc = (b'\xF0' +
UnicodeEncodeError: 'ascii' codec can't encode character '\xe4' in position 0: ordinal not in range(128)
Note that we are trying to encode in 'datamatrix.EDIFACT'. But the error message says there is a failure when encoding to 'ascii'. We should catch this exception and re-raise an exception that say 'ä' is an invalid datamatrix.EDIFACT character.
Similar things happen in other codecs.
The text was updated successfully, but these errors were encountered:
Trying to encode a character which is not supported by a codec will raise an exception (=> good). However, the error message is a bit misleading in some cases.
Example:
Note that we are trying to encode in 'datamatrix.EDIFACT'. But the error message says there is a failure when encoding to 'ascii'. We should catch this exception and re-raise an exception that say 'ä' is an invalid datamatrix.EDIFACT character.
Similar things happen in other codecs.
The text was updated successfully, but these errors were encountered: