comparison myrss/myrss_app.py @ 88:583400dc28a0

myrss: update user-agent string to "Mozilla/5.0 Browser" after some servers complain about "Mozilla/5.0"; show exception type in top-level exception handler log message
author paulo
date Thu, 12 Jan 2017 00:59:05 -0700
parents 51f0da3da721
children 8214951cb8e7
comparison
equal deleted inserted replaced
9:49cdc4dc0890 10:9c2dd6337045
159 159
160 160
161 def _fetch_url(url): 161 def _fetch_url(url):
162 try: 162 try:
163 logging.info("processing %s" % url) 163 logging.info("processing %s" % url)
164 feed = urllib2.urlopen(urllib2.Request(url, headers={"User-Agent": "Mozilla/5.0"}), timeout=URLOPEN_TIMEOUT) 164 feed = urllib2.urlopen(urllib2.Request(url, headers={"User-Agent": "Mozilla/5.0 Browser"}), timeout=URLOPEN_TIMEOUT)
165 except urllib2.HTTPError as e: 165 except urllib2.HTTPError as e:
166 logging.info("(%s) %s" % (url, e)) 166 logging.info("(%s) %s" % (url, e))
167 return None 167 return None
168 168
169 return feed 169 return feed
207 try: 207 try:
208 feed = _fetch_url(url) 208 feed = _fetch_url(url)
209 if feed is not None: 209 if feed is not None:
210 docfeed = _process_feed(feed) 210 docfeed = _process_feed(feed)
211 except Exception as e: 211 except Exception as e:
212 logging.info("(%s) exception: %s" % (url, e)) 212 logging.info("(%s) exception: (%s) %s" % (url, type(e), e))
213 self._output_queue.put((idx, docfeed)) 213 self._output_queue.put((idx, docfeed))
214 214
215 215
216 def main(input_queue, output_queue, lock): 216 def main(input_queue, output_queue, lock):
217 ret = '' 217 ret = ''