7 import requests.exceptions
16 logger = logging.getLogger(APP_CONSTS.LOGGER_NAME)
17 logger.setLevel(logging.DEBUG)
20 ch = logging.StreamHandler()
21 ch.setLevel(logging.DEBUG)
24 formatter = logging.Formatter(
'%(asctime)s - %(name)s - %(levelname)s - %(message)s')
27 ch.setFormatter(formatter)
35 if __name__ ==
'__main__':
39 url =
'https://ukranews.com/rss/news_all_uk.xml' 42 headers = {
'Accept-Language':
'en-US,en;q=0.8,en;q=0.6,us;q=0.4,us;q=0.2,ja;q=0.2',
'Accept-Encoding':
'gzip, deflate',
'--disable-setuid-sandbox':
'',
'Connection':
'close',
'Accept':
'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'User-Agent':
'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome 49.0.2623.87 Safari/537.36',
'Cache-Control':
'no-cache',
'--log-chrome-debug-log':
'',
'Referer':
u'http://ukranews.com/rss/news_all_uk.xml',
'--allow-running-insecure-content':
'',
'Pragma':
'no-cache',
'--user-data-dir-zip':
'/tmp/custom_profile_fb_noimg50b.zip',
'--allow-file-access-from-files':
'',
'--disable-web-security':
''}
43 allow_redirects =
True 52 impl_res = requestsRedirect.request(url=url,
56 allowRedirects=allow_redirects,
57 proxySetting=proxy_setting,
60 maxRedirects=max_redirects,
63 logger.debug(
"!!! impl_res.headers: %s",
varDump(impl_res.headers))
64 logger.debug(
"!!! impl_res.url: %s", str(impl_res.url))
66 except requests.exceptions.RequestException, err:
67 logger.error(
"!!! RequestException: %s", str(err))
68 except Exception, err:
69 logger.error(
"!!! Exception: %s", str(err))
def varDump(obj, stringify=True, strTypeMaxLen=256, strTypeCutSuffix='...', stringifyType=1, ignoreErrors=False, objectsHash=None, depth=0, indent=2, ensure_ascii=False, maxDepth=10)