utf-8 decoding in ein try-except gepackt

This commit is contained in:
bernd 2023-07-17 19:07:37 +02:00
parent 381bd390df
commit 06c4d75f27

View file

@ -132,9 +132,18 @@ def receive_buffer_is_valid(raw_data):
param 1: byte object
return: boolean
'''
if raw_data.decode('utf-8', 'strict') in ('0', '1'):
logging.debug('Argument is valid: {}'.format(raw_data))
return True
try:
if raw_data.decode('utf-8', 'strict') in ('0', '1'):
logging.debug('Argument is valid: {}'.format(raw_data))
return True
except UnicodeDecodeError as err:
logging.error('Argument is not valid unicode')
logging.error(err)
return False
except Exception as err:
logging.error('Exception occurred')
logging.error(err)
return False
logging.debug('Argument is not valid: {}'.format(raw_data))
return False