From: Oleg Broytman Date: Mon, 20 Nov 2023 17:33:42 +0000 (+0300) Subject: Fix(Py3): `urllib` writes its files as bytes X-Git-Tag: 5.0.0~7 X-Git-Url: https://git.phdru.name/?p=bookmarks_db.git;a=commitdiff_plain;h=c51ce847534af946e10cbbb55ac22fd9adfe42b3 Fix(Py3): `urllib` writes its files as bytes --- 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