utf-8 decoding in ein try-except gepackt
This commit is contained in:
parent
381bd390df
commit
06c4d75f27
1 changed files with 12 additions and 3 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue