ettoreleandrotognoli / python-ami

Python AMI Client
BSD 3-Clause "New" or "Revised" License
107 stars 66 forks source link

'utf-8' codec can't decode byte: invalid continuation byte #7

Closed jellex closed 7 years ago

jellex commented 7 years ago

Hello 0/

My problem like Issue #3, but other error: on console I received error

utf-8' codec can't decode byte 0xd1 in position 146: invalid continuation byte

The fact is that my db contains values in latin-1 encoding. I found the problem here. Yet I solved the problem so

# yield pack.decode('utf-8')
yield pack.decode('latin-1')

As a solution to propose to establish the value of the encoding parameter, which could be given when creating an instance AMIClient or do something like

try:
    yield pack.decode('utf-8')
except UnicodeDecodeError:
    yield pack.decode('latin-1')

Example of part byte received from asterisk: b'CallerIDName: \xc2\xe8\xf2\xe0\xeb\xe8\xe9 \xca\xe0\xeb\xe8\xed\xe8\xed'

ettoreleandrotognoli commented 7 years ago

Hello! Thanks for your contribution! I believe this will solve your problem.

jellex commented 7 years ago

Yeah, it solve my problem. Thank You very much