3 HCE project, Python bindings, DC dependencies 4 The requests research tests. 7 @author bgv bgv.hce@gmail.com 8 @link: http://hierarchical-cluster-engine.com/ 9 @copyright: Copyright © 2017 IOIX Ukraine 10 @license: http://hierarchical-cluster-engine.com/license/ 16 import requests.exceptions
25 logger = logging.getLogger(
'hce')
26 logger.setLevel(logging.DEBUG)
29 ch = logging.StreamHandler()
30 ch.setLevel(logging.DEBUG)
33 formatter = logging.Formatter(
'%(asctime)s - %(name)s - %(levelname)s - %(message)s')
36 ch.setFormatter(formatter)
47 url =
'https://api.github.com/user' 111 url =
'http://rssfeeds.usatoday.com/~/477506178/0/usatodaycomworld-topstories~London-fights-pollution-by-charging-drivers-of-older-polluting-cars/' 118 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',
'Cache-Control':
'no-cache',
'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/52.0.2743.82 Safari/537.36',
'Connection':
'close',
'--allow-running-insecure-content':
'',
'Pragma':
'no-cache',
'--disable-setuid-sandbox':
'',
'--allow-file-access-from-files':
'',
'--disable-web-security':
''}
119 allowRedirects =
True 128 res = reqv.request(url, method, timeout, headers, allowRedirects, proxySetting, auth, data, maxRedirects, filters)
131 print(
'Url: ' + str(res.request.url))
132 print(
'res.cookies: ' +
varDump(res.cookies) +
' type: ' + str(
type(res.cookies)))
133 cookies = requests.utils.dict_from_cookiejar(res.cookies)
134 print(
'cookies: ' +
varDump(cookies) +
' type: ' + str(
type(cookies)))
136 print(
'len(res.content) = ' + str(len(res.content)))
151 except requests.exceptions.RequestException, err:
152 print (
"!!! RequestException: " + str(err))
153 except Exception, err:
154 print (
"!!! Exception: " + 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)
def getTracebackInfo(linesNumberMax=None)