Skip to content

Commit

Permalink
Do not try to detect None charset
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikek committed Dec 9, 2023
1 parent a77d5d5 commit d861c09
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions ESSArch_Core/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,9 @@ def validate_remote_url(url):
def get_charset(byte_str):
decoded_flag = False
guess = chardet.detect(byte_str)
charsets = [settings.DEFAULT_CHARSET, 'utf-8', 'windows-1252', guess['encoding']]
charsets = [settings.DEFAULT_CHARSET, 'utf-8', 'windows-1252']
if guess['encoding'] is not None:
charsets.append(guess['encoding'])
for c in sorted(set(charsets), key=charsets.index):
logger.debug('Trying to decode response in {}'.format(c))
try:
Expand All @@ -603,8 +605,8 @@ def get_charset(byte_str):
logger.debug('Decoded response in {}'.format(c))
return c
else:
logger.error('Failed to decode response in {}'.format(c))
return 'Unknown'
logger.warning('Failed to decode response in {}'.format(sorted(set(charsets))))
return None


def get_filename_from_file_obj(file_obj, name):
Expand Down

0 comments on commit d861c09

Please sign in to comment.