本文整理匯總了Python中urllib3.HTTPConnectionPool方法的典型用法代碼示例。如果您正苦於以下問題:Python urllib3.HTTPConnectionPool方法的具體用法?Python urllib3.HTTPConnectionPool怎麽用?Python urllib3.HTTPConnectionPool使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類urllib3
的用法示例。
在下文中一共展示了urllib3.HTTPConnectionPool方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __http_pool
# 需要導入模塊: import urllib3 [as 別名]
# 或者: from urllib3 import HTTPConnectionPool [as 別名]
def __http_pool(self):
"""
Create HTTP connection pool
:raise HttpRequestError
:return: urllib3.HTTPConnectionPool
"""
try:
pool = HTTPConnectionPool(self.__cfg.host,
port=self.__cfg.port,
maxsize=self.__cfg.threads,
timeout=Timeout(self.__cfg.timeout, read=self.__cfg.timeout),
block=True)
if self._HTTP_DBG_LEVEL <= self.__debug.level:
self.__debug.debug_connection_pool('http_pool_start', pool)
return pool
except Exception as error:
raise HttpRequestError(str(error))
示例2: test_install_fail_no_urlopen_attribute
# 需要導入模塊: import urllib3 [as 別名]
# 或者: from urllib3 import HTTPConnectionPool [as 別名]
def test_install_fail_no_urlopen_attribute(caplog):
mock_pool = mock.patch("scout_apm.instruments.urllib3.HTTPConnectionPool")
with mock_not_attempted, mock_pool as mocked_pool:
# Remove urlopen attribute
del mocked_pool.urlopen
ensure_installed()
assert len(caplog.record_tuples) == 2
assert caplog.record_tuples[0] == (
"scout_apm.instruments.urllib3",
logging.DEBUG,
"Instrumenting urllib3.",
)
logger, level, message = caplog.record_tuples[1]
assert logger == "scout_apm.instruments.urllib3"
assert level == logging.WARNING
assert message.startswith(
"Failed to instrument for Urllib3 HTTPConnectionPool.urlopen: AttributeError"
)
示例3: __init__
# 需要導入模塊: import urllib3 [as 別名]
# 或者: from urllib3 import HTTPConnectionPool [as 別名]
def __init__(self, pSocket, connectString):
Thread.__init__(self)
self.pSocket = pSocket
self.connectString = connectString
o = urlparse(connectString)
try:
self.httpPort = o.port
except:
if o.scheme == "https":
self.httpPort = 443
else:
self.httpPort = 80
self.httpScheme = o.scheme
self.httpHost = o.netloc.split(":")[0]
self.httpPath = o.path
self.cookie = None
if o.scheme == "http":
self.httpScheme = urllib3.HTTPConnectionPool
else:
self.httpScheme = urllib3.HTTPSConnectionPool
示例4: __init__
# 需要導入模塊: import urllib3 [as 別名]
# 或者: from urllib3 import HTTPConnectionPool [as 別名]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# Additionally to adding our variant of the usual HTTP and HTTPS
# pool classes, also add these for some variants of the default schemes
# that are limited to some specific address family only
self.pool_classes_by_scheme = {}
for scheme, ConnectionPool in (("http", HTTPConnectionPool), ("https", HTTPSConnectionPool)):
self.pool_classes_by_scheme[scheme] = ConnectionPool
for name in AF2NAME.values():
self.pool_classes_by_scheme["{0}+{1}".format(scheme, name)] = ConnectionPool
self.key_fn_by_scheme["{0}+{1}".format(scheme, name)] = self.key_fn_by_scheme[scheme]
# These next two are only required to ensure that our custom `scheme` values
# will be passed down to the `*ConnectionPool`s and finally to the actual
# `*Connection`s as parameter
示例5: test_request_no_absolute_url
# 需要導入模塊: import urllib3 [as 別名]
# 或者: from urllib3 import HTTPConnectionPool [as 別名]
def test_request_no_absolute_url(caplog, tracked_request):
ensure_installed()
delete_absolute_url = delete_attributes(urllib3.HTTPConnectionPool, "_absolute_url")
with httpretty.enabled(allow_net_connect=False), delete_absolute_url:
httpretty.register_uri(
httpretty.GET, "https://example.com/", body="Hello World!"
)
http = urllib3_cert_pool_manager()
response = http.request("GET", "https://example.com")
assert response.status == 200
assert response.data == b"Hello World!"
assert len(tracked_request.complete_spans) == 1
span = tracked_request.complete_spans[0]
assert span.operation == "HTTP/GET"
assert span.tags["url"] == "Unknown"
示例6: __init__
# 需要導入模塊: import urllib3 [as 別名]
# 或者: from urllib3 import HTTPConnectionPool [as 別名]
def __init__(self, host, port, useragent=USERAGENT,
connection_class=urllib3.HTTPConnectionPool, **kwargs):
self.useragent = useragent
self._connection = connection_class(host, port, **kwargs)
示例7: askGeorg
# 需要導入模塊: import urllib3 [as 別名]
# 或者: from urllib3 import HTTPConnectionPool [as 別名]
def askGeorg(connectString):
connectString = connectString
o = urlparse(connectString)
try:
httpPort = o.port
except:
if o.scheme == "https":
httpPort = 443
else:
httpPort = 80
httpScheme = o.scheme
httpHost = o.netloc.split(":")[0]
httpPath = o.path
if o.scheme == "http":
httpScheme = urllib3.HTTPConnectionPool
else:
httpScheme = urllib3.HTTPSConnectionPool
conn = httpScheme(host=httpHost, port=httpPort)
response = conn.request("GET", httpPath)
if response.status == 200:
if BASICCHECKSTRING == response.data.strip():
log.info(BASICCHECKSTRING)
return True
conn.close()
return False
示例8: setUp
# 需要導入模塊: import urllib3 [as 別名]
# 或者: from urllib3 import HTTPConnectionPool [as 別名]
def setUp(self):
self.http = urllib3.HTTPConnectionPool('127.0.0.1', port=testenv["wsgi_port"], maxsize=20)
self.recorder = tracer.recorder
self.recorder.clear_spans()
tracer._scope_manager = GeventScopeManager()
示例9: __init__
# 需要導入模塊: import urllib3 [as 別名]
# 或者: from urllib3 import HTTPConnectionPool [as 別名]
def __init__(self, host='localhost', port=9200, http_auth=None,
use_ssl=False, verify_certs=False, ca_certs=None, client_cert=None,
maxsize=10, **kwargs):
super(Urllib3HttpConnection, self).__init__(host=host, port=port, **kwargs)
self.headers = {}
if http_auth is not None:
if isinstance(http_auth, (tuple, list)):
http_auth = ':'.join(http_auth)
self.headers = urllib3.make_headers(basic_auth=http_auth)
pool_class = urllib3.HTTPConnectionPool
kw = {}
if use_ssl:
pool_class = urllib3.HTTPSConnectionPool
if verify_certs:
kw['cert_reqs'] = 'CERT_REQUIRED'
kw['ca_certs'] = ca_certs
kw['cert_file'] = client_cert
elif ca_certs:
raise ImproperlyConfigured("You cannot pass CA certificates when verify SSL is off.")
else:
warnings.warn(
'Connecting to %s using SSL with verify_certs=False is insecure.' % host)
self.pool = pool_class(host, port=port, timeout=self.timeout, maxsize=maxsize, **kw)
示例10: test_install_fail_no_httpconnectionpool
# 需要導入模塊: import urllib3 [as 別名]
# 或者: from urllib3 import HTTPConnectionPool [as 別名]
def test_install_fail_no_httpconnectionpool(caplog):
mock_no_pool = mock.patch(
"scout_apm.instruments.urllib3.HTTPConnectionPool", new=None
)
with mock_not_attempted, mock_no_pool:
ensure_installed()
assert caplog.record_tuples == [
("scout_apm.instruments.urllib3", logging.DEBUG, "Instrumenting urllib3.",),
(
"scout_apm.instruments.urllib3",
logging.DEBUG,
"Couldn't import urllib3.HTTPConnectionPool - probably not installed.",
),
]
示例11: __init__
# 需要導入模塊: import urllib3 [as 別名]
# 或者: from urllib3 import HTTPConnectionPool [as 別名]
def __init__(self, host='localhost', port=9200, http_auth=None,
use_ssl=False, verify_certs=True, ca_certs=None, client_cert=None,
client_key=None, ssl_version=None, ssl_assert_hostname=None,
ssl_assert_fingerprint=None, maxsize=10, headers=None, **kwargs):
super(Urllib3HttpConnection, self).__init__(host=host, port=port, use_ssl=use_ssl, **kwargs)
self.headers = urllib3.make_headers(keep_alive=True)
if http_auth is not None:
if isinstance(http_auth, (tuple, list)):
http_auth = ':'.join(http_auth)
self.headers.update(urllib3.make_headers(basic_auth=http_auth))
# update headers in lowercase to allow overriding of auth headers
if headers:
for k in headers:
self.headers[k.lower()] = headers[k]
self.headers.setdefault('content-type', 'application/json')
ca_certs = CA_CERTS if ca_certs is None else ca_certs
pool_class = urllib3.HTTPConnectionPool
kw = {}
if use_ssl:
pool_class = urllib3.HTTPSConnectionPool
kw.update({
'ssl_version': ssl_version,
'assert_hostname': ssl_assert_hostname,
'assert_fingerprint': ssl_assert_fingerprint,
})
if verify_certs:
if not ca_certs:
raise ImproperlyConfigured("Root certificates are missing for certificate "
"validation. Either pass them in using the ca_certs parameter or "
"install certifi to use it automatically.")
kw.update({
'cert_reqs': 'CERT_REQUIRED',
'ca_certs': ca_certs,
'cert_file': client_cert,
'key_file': client_key,
})
else:
warnings.warn(
'Connecting to %s using SSL with verify_certs=False is insecure.' % host)
self.pool = pool_class(host, port=port, timeout=self.timeout, maxsize=maxsize, **kw)