HCE Project Python language Distributed Tasks Manager Application, Distributed Crawler Application and client API bindings.  2.0.0-chaika
Hierarchical Cluster Engine Python language binding
ftest_RequestsRedirectWrapper.py
Go to the documentation of this file.
1 #!/usr/bin/python
2 # coding: utf-8
3 
4 import os
5 import sys
6 import logging
7 import requests.exceptions
8 
9 from dc_crawler.RequestsRedirectWrapper import RequestsRedirectWrapper
10 from app.Utils import varDump
11 import app.Consts as APP_CONSTS
12 
13 
14 def getLogger():
15  # create logger
16  logger = logging.getLogger(APP_CONSTS.LOGGER_NAME)
17  logger.setLevel(logging.DEBUG)
18 
19  # create console handler and set level to debug
20  ch = logging.StreamHandler()
21  ch.setLevel(logging.DEBUG)
22 
23  # create formatter
24  formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
25 
26  # add formatter to ch
27  ch.setFormatter(formatter)
28 
29  # add ch to logger
30  logger.addHandler(ch)
31 
32  return logger
33 
34 
35 if __name__ == '__main__':
36 
37  logger = getLogger()
38 
39  url = 'https://ukranews.com/rss/news_all_uk.xml'
40  method = 'GET'
41  timeout = 10.0
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
44  proxy_setting = None
45  auth = None
46  data = None
47  max_redirects = 10
48  filters = None
49 
50  try:
51  requestsRedirect = RequestsRedirectWrapper()
52  impl_res = requestsRedirect.request(url=url,
53  method=method,
54  timeout=timeout,
55  headers=headers,
56  allowRedirects=allow_redirects,
57  proxySetting=proxy_setting,
58  auth=auth,
59  data=data,
60  maxRedirects=max_redirects,
61  filters=filters)
62 
63  logger.debug("!!! impl_res.headers: %s", varDump(impl_res.headers))
64  logger.debug("!!! impl_res.url: %s", str(impl_res.url))
65 
66  except requests.exceptions.RequestException, err:
67  logger.error("!!! RequestException: %s", str(err))
68  except Exception, err:
69  logger.error("!!! Exception: %s", str(err))
70 
def varDump(obj, stringify=True, strTypeMaxLen=256, strTypeCutSuffix='...', stringifyType=1, ignoreErrors=False, objectsHash=None, depth=0, indent=2, ensure_ascii=False, maxDepth=10)
Definition: Utils.py:410