faucamp / python-gsmmodem

Python module to control a GSM modem attached to the system: send/receive SMS messages, handle calls, etc
GNU Lesser General Public License v3.0
385 stars 303 forks source link

Invalid accented character decoding #114

Closed daibe closed 1 year ago

daibe commented 1 year ago

Decoding accented characters causes a UnicodeDecodeError:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.9/threading.py", line 954, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.9/threading.py", line 892, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.9/dist-packages/gsmmodem/serial_comms.py", line 103, in _readLoop
    line = rxBuffer[:-readTermLen].decode()
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9 in position 33: invalid continuation byte
...

Should add the Western European encoding 'iso-8859-1' to correctly decode bytes, like so: line = rxBuffer[:-readTermLen].decode()