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 #3

Closed firkeuf closed 7 years ago

firkeuf commented 7 years ago

Hello

If set up event listener, some time, on console received error

'utf-8' codec can't decode byte 0xd0 in position 1023: unexpected end of data

and listener stop working

I try find why and find that it came from here -> here

Example of byte received from asterisk: b'Local/+38097XXXXXXX@corp-00000014;2\r\nContext: macro-out_roundrobin_gateway\r\nExtension: s\r\nPriority: 2\r\nApplication: Set\r\nAppData: GO_COUNT=0\r\nUniqueid: 1479133224.1443\r\n\r\nEvent: VarSet\r\nPrivilege: dialplan,all\r\nTimestamp: 1479133224.599046\r\nChannel: Local/+38097XXXXXXX@corp-00000014;2\r\nVariable: GO_COUNT\r\nValue: 0\r\nUniqueid: 1479133224.1443\r\n\r\nEvent: VarSet\r\nPrivilege: dialplan,all\r\nTimestamp: 1479133224.599134\r\nChannel: Local/+38097XXXXXXX@corp-00000014;2\r\nVariable: MACRO_DEPTH\r\nValue: 1\r\nUniqueid: 1479133224.1443\r\n\r\nEvent: VarSet\r\nPrivilege: dialplan,all\r\nTimestamp: 1479133224.599360\r\nChannel: Local/+38097XXXXXXX@corp-00000014;2\r\nVariable: DB_RESULT\r\nValue: 2\r\nUniqueid: 1479133224.1443\r\n\r\nEvent: Newexten\r\nPrivilege: dialplan,all\r\nTimestamp: 1479133224.599928\r\nChannel: Local/+38097XXXXXXX@corp-00000014;2\r\nContext: macro-out_roundrobin_gateway\r\nExtension: s\r\nPriority: 3\r\nApplication: NoOp\r\nAppData: -- \xd0\x93\xd0\xa0\xd0\xa3\xd0\x9f\xd0\x9f\xd0\x90 Kharkiv \xd0\xb1\xd1\x83\xd0\xb4\xd0\xb5\xd1\x82\xd1\x8c \xd0\xbf\xd1\x8b\xd1\x82\xd0\xb0\xd1\x82\xd1\x8c\xd1\x81\xd1\x8f \xd0\x97\xd0\x92\xd0\x9e\xd0\x9d\xd0\x98\xd0\xa2\xd0\xac \xd0\xbd\xd0\xb0 +38097XXXXXXX\xd1\x87\xd0\xb5\xd1\x80\xd0\xb5\xd0\xb7 LINEOUTKS \xd0\xbb\xd0'

ettoreleandrotognoli commented 7 years ago

I will think about your suggestion I believe this error was caused because decode was called on a segment of packet not on a full packet, the solution was committed in dev branch https://github.com/ettoreleandrotognoli/python-ami/commit/fd549364118d2f3dbd9d4721f83f953b5fb84129

firkeuf commented 7 years ago

Yes it works Thank You