diff options
author | Cédric Bonhomme <kimble.mandel@gmail.com> | 2013-09-08 11:23:25 +0200 |
---|---|---|
committer | Cédric Bonhomme <kimble.mandel@gmail.com> | 2013-09-08 11:23:25 +0200 |
commit | 18ec77e80632b67a3bf268fba3182c7297517b5f (patch) | |
tree | 24675baf7b59c062795717b38c139f9b6927b344 /source | |
parent | Added a function which opens a URL safely. (diff) | |
download | newspipe-18ec77e80632b67a3bf268fba3182c7297517b5f.tar.gz newspipe-18ec77e80632b67a3bf268fba3182c7297517b5f.tar.bz2 newspipe-18ec77e80632b67a3bf268fba3182c7297517b5f.zip |
Log errors when trying to fetch an URL.
Diffstat (limited to 'source')
-rwxr-xr-x | source/log.py | 2 | ||||
-rwxr-xr-x | source/utils.py | 10 |
2 files changed, 10 insertions, 2 deletions
diff --git a/source/log.py b/source/log.py index 071ab5c8..5db5d838 100755 --- a/source/log.py +++ b/source/log.py @@ -36,7 +36,7 @@ class Log(object): """ import logging self.logger = logging.getLogger("pyaggr3g470r") - hdlr = logging.FileHandler('./var/access.log') + hdlr = logging.FileHandler('./var/pyaggr3g470r.log') formater = logging.Formatter('%(asctime)s %(levelname)s %(message)s') hdlr.setFormatter(formater) self.logger.addHandler(hdlr) diff --git a/source/utils.py b/source/utils.py index e2bf69ab..4699a20b 100755 --- a/source/utils.py +++ b/source/utils.py @@ -68,6 +68,9 @@ url_finders = [ \ re.compile("'\\<((mailto:)|)[-A-Za-z0-9\\.]+@[-A-Za-z0-9\\.]+") \ ] +import log +pyaggr3g470r_log = log.Log() + @contextmanager def opened_w_error(filename, mode="r"): try: @@ -97,13 +100,18 @@ def open_url(url): except urllib.error.HTTPError as e: # server couldn't fulfill the request errors.append((url, e.code, \ - http.server.BaseHTTPRequestHandler.responses[e.code][1])) + http.server.BaseHTTPRequestHandler.responses[e.code][1])) + pyaggr3g470r_log.error(url + " " + e.code + " " + \ + http.server.BaseHTTPRequestHandler.responses[e.code][1]) except urllib.error.URLError as e: # failed to reach the server if type(e.reason) == str: errors.append((url, e.reason, e.reason)) + pyaggr3g470r_log.error(URL + " " + e.reason) else: errors.append((url, e.reason.errno, e.reason.strerror)) + pyaggr3g470r_log.error(URL + " " + e.reason.errno + " " + \ + e.reason.strerror) return (False, errors) def generate_qr_code(article): |