當前位置: 首頁>>代碼示例>>Python>>正文


Python urllib3.HTTPConnectionPool方法代碼示例

本文整理匯總了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)) 
開發者ID:stanislav-web,項目名稱:OpenDoor,代碼行數:20,代碼來源:http.py

示例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"
    ) 
開發者ID:scoutapp,項目名稱:scout_apm_python,代碼行數:22,代碼來源:test_urllib3.py

示例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 
開發者ID:artikrh,項目名稱:HackTheBox,代碼行數:22,代碼來源:reGeorgSocksProxy.py

示例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 
開發者ID:ipfs-shipyard,項目名稱:py-ipfs-http-client,代碼行數:18,代碼來源:requests_wrapper.py

示例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" 
開發者ID:scoutapp,項目名稱:scout_apm_python,代碼行數:19,代碼來源:test_urllib3.py

示例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) 
開發者ID:wtolson,項目名稱:gnsq,代碼行數:6,代碼來源:httpclient.py

示例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 
開發者ID:artikrh,項目名稱:HackTheBox,代碼行數:28,代碼來源:reGeorgSocksProxy.py

示例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() 
開發者ID:instana,項目名稱:python-sensor,代碼行數:7,代碼來源:test_gevent.py

示例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) 
開發者ID:hvandenb,項目名稱:splunk-elasticsearch,代碼行數:29,代碼來源:http_urllib3.py

示例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.",
        ),
    ] 
開發者ID:scoutapp,項目名稱:scout_apm_python,代碼行數:17,代碼來源:test_urllib3.py

示例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) 
開發者ID:iagcl,項目名稱:watchmen,代碼行數:48,代碼來源:http_urllib3.py


注:本文中的urllib3.HTTPConnectionPool方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。