post_process.redirect: Specify user-agent
authorFrançois Boulogne <fboulogne sciunto org>
Mon, 30 Sep 2013 11:46:33 +0000 (13:46 +0200)
committerW. Trevor King <wking@tremily.us>
Sat, 18 Jan 2014 18:22:41 +0000 (10:22 -0800)
Signed-off-by: François Boulogne <fboulogne sciunto org>
Signed-off-by: W. Trevor King <wking@tremily.us>
rss2email/post_process/redirect.py

index 6ffd6741167b77a34f7364e80dd0ca57e44354ea..d06fcec71a49a2d7476dba99adaa1e93bfc43808 100644 (file)
@@ -24,6 +24,7 @@ This hook finds and uses the real url behind redirects.
 
 import urllib
 import re
+import rss2email
 
 def process(feed, parsed, entry, guid, message):
     # decode message
@@ -37,7 +38,9 @@ def process(feed, parsed, entry, guid, message):
 
     # Remove the redirect and modify the content
     try:
-        direct_link = urllib.request.urlopen(link).geturl()
+        request = urllib.request.Request(link)
+        request.add_header('User-agent', rss2email.feed._USER_AGENT)
+        direct_link = urllib.request.urlopen(request).geturl()
     except:
         return message
     content = re.sub(re.escape(link), direct_link, content, re.MULTILINE)