From c51ce847534af946e10cbbb55ac22fd9adfe42b3 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Mon, 20 Nov 2023 20:33:42 +0300 Subject: [PATCH] Fix(Py3): `urllib` writes its files as bytes --- Robots/bkmk_rurllib_py3.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/Robots/bkmk_rurllib_py3.py b/Robots/bkmk_rurllib_py3.py index 1daec38..73f9b77 100644 --- a/Robots/bkmk_rurllib_py3.py +++ b/Robots/bkmk_rurllib_py3.py @@ -117,21 +117,19 @@ class robot_urllib_py3(robot_base): ): if encoding and encoding not in possible_encodings: possible_encodings.append(encoding) - content = None - for encoding in possible_encodings: - infile = open(fname, 'rt', encoding=encoding) - try: - content = infile.read() - except UnicodeDecodeError: - infile.close() - continue - else: - break + content = e = None + infile = open(fname, 'rb') + try: + content = infile.read() + except Exception as e: + content = None + finally: infile.close() if content is None: + e = str(e) return ( - 'ERROR: File encoding was not recognized', + 'ERROR: ' + e, None, None, None, None ) return None, None, None, headers, content -- 2.39.5