From: W. Trevor King Date: Sun, 28 Sep 2014 17:47:15 +0000 (-0700) Subject: post_process.redirect: Log exceptions as warnings X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=3d2b5055b53f50870d22c4273e413b4893af9480;p=rss2email.git post_process.redirect: Log exceptions as warnings When we hit an exception trying to unwind any redirects, just print the exception and leave the link with its original value. This commit also alphabetizes the standard library imports, and splits off the local import following PEP 8's suggested groupings [1]. [1]: http://legacy.python.org/dev/peps/pep-0008/#imports Signed-off-by: W. Trevor King --- diff --git a/rss2email/post_process/redirect.py b/rss2email/post_process/redirect.py index 289fc65..b237fbc 100644 --- a/rss2email/post_process/redirect.py +++ b/rss2email/post_process/redirect.py @@ -22,10 +22,16 @@ statistics. You may want to avoid this for privacy or for durability. This hook finds and uses the real url behind redirects. """ -import urllib +import logging import re +import urllib + import rss2email + +LOG = _logging.getLogger(__name__) + + def process(feed, parsed, entry, guid, message): # decode message encoding = message.get_charsets()[0] @@ -52,7 +58,9 @@ def process(feed, parsed, entry, guid, message): request = urllib.request.Request(link) request.add_header('User-agent', rss2email.feed._USER_AGENT) direct_link = urllib.request.urlopen(request).geturl() - except: + except Exception as e: + LOG.warning('could not follow redirect for {}: {}'.format( + linke, e)) continue content = re.sub(re.escape(link), direct_link, content, re.MULTILINE)