本文整理汇总了Python中requests.Session.__init__方法的典型用法代码示例。如果您正苦于以下问题:Python Session.__init__方法的具体用法?Python Session.__init__怎么用?Python Session.__init__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类requests.Session
的用法示例。
在下文中一共展示了Session.__init__方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from requests import Session [as 别名]
# 或者: from requests.Session import __init__ [as 别名]
def __init__(self):
Session.__init__(self)
self.headers = {
"User-Agent": "Oruga Amarilla transmit API",
"Content-type": "application/x-www-form-urlencoded",
"Accept": "text/plain"
}
with myfile.db('config.mod',':') as p:
for k in p:
if k[0]=='base':
self.myID = k[1]
debug.out2('This site name',self.myID)
elif k[0]=='remote':
self.server = k[1]
debug.out2('Sending to server',self.server)
elif k[0]=='header':
self.headers[k[1]] = k[2]
debug.out2('Adding POST header','{}:{}'.format(k[1],k[2]))
elif k[0] in {'interval','pause'}:
self.interval = int(k[1])
debug.out2('Interval set to',self.interval)
elif k[0] in {'iters','repeat'}:
i = int(k[1])
self.repeat = int(i)
if not i: i = 'infinity'
debug.out2('Setting iterations to',i)
self.auth = (self.myID,self.passwd)
示例2: __init__
# 需要导入模块: from requests import Session [as 别名]
# 或者: from requests.Session import __init__ [as 别名]
def __init__(self, *args, **kwargs):
Session.__init__(self, *args, **kwargs)
self.timeout = 20.0
if TIMEOUT_ADAPTER_NEEDED:
self.mount("http://", HTTPAdapterWithReadTimeout())
self.mount("https://", HTTPAdapterWithReadTimeout())
示例3: __init__
# 需要导入模块: from requests import Session [as 别名]
# 或者: from requests.Session import __init__ [as 别名]
def __init__(self, options, *args, **kwargs):
Session.__init__(self, *args, **kwargs)
adapter = HTTPAdapter(max_retries=retry)
self.mount('http://', adapter)
self.mount('https://', adapter)
self.verify = options.ssl_verify
self.proxy = options.proxy
if options.http_headers:
self.headers.update(self.split_header(options.http_headers))
self.headers.update({"User-Agent": FIREFOX_UA})
示例4: __init__
# 需要导入模块: from requests import Session [as 别名]
# 或者: from requests.Session import __init__ [as 别名]
def __init__(self, config=dict(), *args, **kwargs):
Session.__init__(self, *args, **kwargs)
adapter = HTTPAdapter(max_retries=retry)
self.mount('http://', adapter)
self.mount('https://', adapter)
self.verify = config.get("ssl_verify")
self.proxy = config.get("proxy")
if config.get("http_headers"):
self.headers.update(self.split_header(config.get("http_headers")))
self.headers.update({"User-Agent": FIREFOX_UA})
示例5: __init__
# 需要导入模块: from requests import Session [as 别名]
# 或者: from requests.Session import __init__ [as 别名]
def __init__(self, pool=None, minthreads=1, maxthreads=4, **kwargs):
"""Creates a twisted aware Session
Notes
~~~~~
* If you provide both `pool` and `max_workers`, the latter is
ignored and provided threadpool is used as is.
"""
requestsSession.__init__(self, **kwargs)
if pool is None:
pool = ThreadPool(minthreads=minthreads, maxthreads=maxthreads)
self.pool = pool
pool.start()
示例6: __init__
# 需要导入模块: from requests import Session [as 别名]
# 或者: from requests.Session import __init__ [as 别名]
def __init__(self, pool=None, minthreads=1, maxthreads=4, **kwargs):
"""Creates a twisted aware Session
Notes
~~~~~
* If you provide both `pool` and `max_workers`, the latter is
ignored and provided threadpool is used as is.
"""
requestsSession.__init__(self, **kwargs)
self.ownPool = False
if pool is None:
self.ownPool = True
pool = ThreadPool(minthreads=minthreads, maxthreads=maxthreads)
# unclosed ThreadPool leads to reactor hangs at shutdown
# this is a problem in many situation, so better enforce pool stop here
reactor.addSystemEventTrigger("before", "shutdown", lambda:pool.stop())
self.pool = pool
if self.ownPool:
pool.start()
示例7: __init__
# 需要导入模块: from requests import Session [as 别名]
# 或者: from requests.Session import __init__ [as 别名]
def __init__(self, options, *args, **kwargs):
Session.__init__(self, *args, **kwargs)
self.verify = options.ssl_verify
if options.http_headers:
self.headers.update(self.split_header(options.http_headers))
self.headers.update({"User-Agent": FIREFOX_UA})
示例8: __init__
# 需要导入模块: from requests import Session [as 别名]
# 或者: from requests.Session import __init__ [as 别名]
def __init__(self, *args, **kwargs):
Session.__init__(self, *args, **kwargs)
self.referer = None
示例9: __init__
# 需要导入模块: from requests import Session [as 别名]
# 或者: from requests.Session import __init__ [as 别名]
def __init__(self, *args, **kwargs):
Session.__init__(self, *args, **kwargs)