X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;ds=sidebyside;f=Robots%2Fbkmk_rurllib_py3.py;h=ae88b1956f54e5f894f9ae2c584258408e5cfa9b;hb=2b3829aef193cb1951989a8cf97a96dcbfc084a1;hp=1da8ec879e96925e40a8ab9cb9fe2e54407ffb7c;hpb=dd8d2bd3a0f9bf4e09f58d7289437cf43350f373;p=bookmarks_db.git diff --git a/Robots/bkmk_rurllib_py3.py b/Robots/bkmk_rurllib_py3.py index 1da8ec8..ae88b19 100644 --- a/Robots/bkmk_rurllib_py3.py +++ b/Robots/bkmk_rurllib_py3.py @@ -11,6 +11,7 @@ __license__ = "GNU GPL" __all__ = ['robot_urllib_py3'] +import http.client import socket import sys import urllib.request @@ -42,6 +43,8 @@ class MyURLopener(urllib.request.URLopener): http_error_303 = http_error_301 # Error 307 -- relocated (temporarily) http_error_307 = http_error_301 + # Error 308 -- relocated (permanently) + http_error_308 = http_error_301 # Error 401 -- authentication required def http_error_401(self, url, fp, errcode, errmsg, headers, data=None): @@ -114,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: + 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 @@ -136,7 +137,7 @@ class robot_urllib_py3(robot_base): except RedirectException as e: return None, e.errcode, e.newurl, None, None - except OSError as e: + except (OSError, http.client.IncompleteRead) as e: error = str(e) self.log(' Error: %s' % error) return error, None, None, None, None