gawel / panoramisk

asyncio based library to play with asterisk
https://panoramisk.readthedocs.io/
MIT License
151 stars 50 forks source link

(feat) fast agi: decode errors #106

Closed zt50tz closed 1 year ago

zt50tz commented 2 years ago

Hello!

Sometimes, asterisk can pull truncated data to agi request. Something like this:

b'agi_network: yes\nagi_network_script: call_income\nagi_request: agi://127.0.0.1:4574/call_income\nagi_channel: SIP/*****-00011487\nagi_language: en\nagi_type: SIP\nagi_uniqueid: 1648407597.170145\nagi_version: 16.17.0\nagi_callerid: ****\nagi_calleridname: \xd0\x90\xd0\xbb\xd0\xb5\xd0\xba\xd1\x81\xd0\xb5\xd0\xb9, Volkswagen Passat, K129\xd0\nagi_callingpres: 0\nagi_callingani2: 0\nagi_callington: 0\nagi_callingtns: 0\nagi_dnid: 74991166525\nagi_rdnis: *****\nagi_context: macro-dial-ringall-predial-hook\nagi_extension: s\nagi_priority: 1\nagi_enhanced: 0.0\nagi_accountcode: \nagi_threadid: 140011921778432\nagi_arg_1: 302-303-304-306-307-308-309-310-311-312-313-314-315-320-321-323-329-339-340-341-342-318-346-347-348-349-10091-331-350'

So, if we try just to decode — it throws UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd0 in position 310: invalid continuation byte.

Will be nice to pass decode errors argument like .decode("utf-8", errors="ignore") to decode pass much well (than exception):

'agi_network: yes\nagi_network_script: call_income\nagi_request: agi://127.0.0.1:4574/call_income\nagi_channel: SIP/*****-00011487\nagi_language: en\nagi_type: SIP\nagi_uniqueid: 1648407597.170145\nagi_version: 16.17.0\nagi_callerid: ****\nagi_calleridname: Алексей, Volkswagen Passat, K129\nagi_callingpres: 0\nagi_callingani2: 0\nagi_callington: 0\nagi_callingtns: 0\nagi_dnid: 74991166525\nagi_rdnis: *****\nagi_context: macro-dial-ringall-predial-hook\nagi_extension: s\nagi_priority: 1\nagi_enhanced: 0.0\nagi_accountcode: \nagi_threadid: 140011921778432\nagi_arg_1: 302-303-304'

I add one more parameter to avoid this situation:

fast_agi.Application(decode_errors="ignore")

Thank you for your library!

gawel commented 2 years ago

The PR looks fine but it looks like tests are freezing on github actions. Cant be merged until the problem persist

zt50tz commented 2 years ago

Hi! Can you rerun checks, please?

ludovic-gasc commented 2 years ago

Hi! Can you rerun checks, please?

Done.