I got this error when I was trying to convert a char (or string) to bytes
, the code was something like this with Python 2.7:
# -*- coding: utf-8 -*-
print( bytes('ò') )
This is the way of Python 2.7 when dealing with unicode chars.
This won't work with Python 3.6, since bytes
require an extra argument for encoding, but this can be little tricky, since different encoding may output different result:
print( bytes('ò', 'iso_8859_1') ) # prints: b'\xf2'
print( bytes('ò', 'utf-8') ) # prints: b'\xc3\xb2'
In my case I had to use iso_8859_1
when encoding bytes in order to solve the issue.
Hope this helps someone.