• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python urllib3.HTTPSConnectionPool类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中urllib3.HTTPSConnectionPool的典型用法代码示例。如果您正苦于以下问题:Python HTTPSConnectionPool类的具体用法?Python HTTPSConnectionPool怎么用?Python HTTPSConnectionPool使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了HTTPSConnectionPool类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_assert_fingerprint_sha256

    def test_assert_fingerprint_sha256(self):
        https_pool = HTTPSConnectionPool("localhost", self.port, cert_reqs="CERT_REQUIRED", ca_certs=DEFAULT_CA)

        https_pool.assert_fingerprint = (
            "9A:29:9D:4F:47:85:1C:51:23:F5:9A:A3:" "0F:5A:EF:96:F9:2E:3C:22:2E:FC:E8:BC:" "0E:73:90:37:ED:3B:AA:AB"
        )
        https_pool.request("GET", "/")
开发者ID:balagopalraj,项目名称:clearlinux,代码行数:7,代码来源:test_https.py


示例2: test_cert_reqs_as_constant

    def test_cert_reqs_as_constant(self):
        https_pool = HTTPSConnectionPool(self.host, self.port,
                                         cert_reqs=ssl.CERT_REQUIRED)

        https_pool.ca_certs = DEFAULT_CA_BAD
        # if we pass in an invalid value it defaults to CERT_NONE
        self.assertRaises(SSLError, https_pool.request, 'GET', '/')
开发者ID:1T,项目名称:urllib3,代码行数:7,代码来源:test_https.py


示例3: test_strip_square_brackets_before_validating

 def test_strip_square_brackets_before_validating(self):
     """Test that the fix for #760 works."""
     if not HAS_IPV6:
         raise SkipTest("Only runs on IPv6 systems")
     https_pool = HTTPSConnectionPool("[::1]", self.port, cert_reqs="CERT_REQUIRED", ca_certs=IPV6_ADDR_CA)
     r = https_pool.request("GET", "/")
     self.assertEqual(r.status, 200)
开发者ID:jnpkrn,项目名称:urllib3,代码行数:7,代码来源:test_https.py


示例4: test_assert_specific_hostname

    def test_assert_specific_hostname(self):
        https_pool = HTTPSConnectionPool('127.0.0.1', self.port,
                                         cert_reqs='CERT_REQUIRED')

        https_pool.ca_certs = DEFAULT_CA
        https_pool.assert_hostname = 'localhost'
        https_pool.request('GET', '/')
开发者ID:1T,项目名称:urllib3,代码行数:7,代码来源:test_https.py


示例5: test_verified_with_context

    def test_verified_with_context(self):
        ctx = util.ssl_.create_urllib3_context(cert_reqs=ssl.CERT_REQUIRED)
        ctx.load_verify_locations(cafile=DEFAULT_CA)
        https_pool = HTTPSConnectionPool(self.host, self.port,
                                         ssl_context=ctx)
        self.addCleanup(https_pool.close)

        conn = https_pool._new_conn()
        self.assertEqual(conn.__class__, VerifiedHTTPSConnection)

        with mock.patch('warnings.warn') as warn:
            r = https_pool.request('GET', '/')
            self.assertEqual(r.status, 200)

            # Modern versions of Python, or systems using PyOpenSSL, don't
            # emit warnings.
            if sys.version_info >= (2, 7, 9) or util.IS_PYOPENSSL:
                self.assertFalse(warn.called, warn.call_args_list)
            else:
                self.assertTrue(warn.called)
                if util.HAS_SNI:
                    call = warn.call_args_list[0]
                else:
                    call = warn.call_args_list[1]
                error = call[0][1]
                self.assertEqual(error, InsecurePlatformWarning)
开发者ID:Lukasa,项目名称:urllib3,代码行数:26,代码来源:test_https.py


示例6: test_assert_hostname_false

    def test_assert_hostname_false(self):
        https_pool = HTTPSConnectionPool('127.0.0.1', self.port,
                                         cert_reqs='CERT_REQUIRED',
                                         ca_certs=DEFAULT_CA)

        https_pool.assert_hostname = False
        https_pool.request('GET', '/')
开发者ID:JasonRepo,项目名称:urllib3,代码行数:7,代码来源:test_https.py


示例7: test_invalid_common_name

 def test_invalid_common_name(self):
     https_pool = HTTPSConnectionPool("127.0.0.1", self.port, cert_reqs="CERT_REQUIRED", ca_certs=DEFAULT_CA)
     try:
         https_pool.request("GET", "/")
         self.fail("Didn't raise SSL invalid common name")
     except SSLError as e:
         self.assertTrue("doesn't match" in str(e))
开发者ID:balagopalraj,项目名称:clearlinux,代码行数:7,代码来源:test_https.py


示例8: test_ssl_verified_with_platform_ca_certs

    def test_ssl_verified_with_platform_ca_certs(self):
        """
        We should rely on the platform CA file to validate authenticity of SSL
        certificates. Since this file is used by many components of the OS,
        such as curl, apt-get, etc., we decided to not touch it, in order to
        not compromise the security of the OS running the test suite (typically
        urllib3 developer's OS).

        This test assumes that httpbin.org uses a certificate signed by a well
        known Certificate Authority.
        """
        try:
            import urllib3.contrib.pyopenssl
        except ImportError:
            raise SkipTest('Test requires PyOpenSSL')
        if (urllib3.connection.ssl_wrap_socket is
                urllib3.contrib.pyopenssl.orig_connection_ssl_wrap_socket):
            # Not patched
            raise SkipTest('Test should only be run after PyOpenSSL '
                           'monkey patching')

        https_pool = HTTPSConnectionPool('httpbin.org', 443,
                                         cert_reqs=ssl.CERT_REQUIRED)

        https_pool.request('HEAD', '/')
开发者ID:JasonRepo,项目名称:urllib3,代码行数:25,代码来源:test_https.py


示例9: test_verified

    def test_verified(self):
        https_pool = HTTPSConnectionPool(self.host, self.port,
                                         cert_reqs='CERT_REQUIRED',
                                         ca_certs=DEFAULT_CA)
        self.addCleanup(https_pool.close)

        conn = https_pool._new_conn()
        self.assertEqual(conn.__class__, VerifiedHTTPSConnection)

        with mock.patch('warnings.warn') as warn:
            r = https_pool.request('GET', '/')
            self.assertEqual(r.status, 200)

            # Modern versions of Python, or systems using PyOpenSSL, don't
            # emit warnings.
            if sys.version_info >= (2, 7, 9) or util.IS_PYOPENSSL \
                    or util.IS_SECURETRANSPORT:
                self.assertFalse(warn.called, warn.call_args_list)
            else:
                self.assertTrue(warn.called)
                if util.HAS_SNI:
                    call = warn.call_args_list[0]
                else:
                    call = warn.call_args_list[1]
                error = call[0][1]
                self.assertEqual(error, InsecurePlatformWarning)
开发者ID:christophermca,项目名称:dotfiles,代码行数:26,代码来源:test_https.py


示例10: TestHTTPS_TLSv1

class TestHTTPS_TLSv1(HTTPSDummyServerTestCase):
    certs = DEFAULT_CERTS.copy()
    certs["ssl_version"] = ssl.PROTOCOL_TLSv1

    def setUp(self):
        self._pool = HTTPSConnectionPool(self.host, self.port)

    def test_set_ssl_version_to_sslv3(self):
        self._pool.ssl_version = ssl.PROTOCOL_SSLv3
        self.assertRaises(SSLError, self._pool.request, "GET", "/")

    def test_ssl_version_as_string(self):
        self._pool.ssl_version = "PROTOCOL_SSLv3"
        self.assertRaises(SSLError, self._pool.request, "GET", "/")

    def test_ssl_version_as_short_string(self):
        self._pool.ssl_version = "SSLv3"
        self.assertRaises(SSLError, self._pool.request, "GET", "/")

    def test_discards_connection_on_sslerror(self):
        self._pool.cert_reqs = "CERT_REQUIRED"
        self.assertRaises(SSLError, self._pool.request, "GET", "/")
        self._pool.ca_certs = DEFAULT_CA
        self._pool.request("GET", "/")

    def test_set_cert_default_cert_required(self):
        conn = VerifiedHTTPSConnection(self.host, self.port)
        conn.set_cert(ca_certs="/etc/ssl/certs/custom.pem")
        self.assertEqual(conn.cert_reqs, "CERT_REQUIRED")
开发者ID:ii0,项目名称:urllib3,代码行数:29,代码来源:test_https.py


示例11: test_invalid_ca_certs

    def test_invalid_ca_certs(self):
        https_pool = HTTPSConnectionPool(self.host, self.port, cert_reqs="CERT_REQUIRED")

        # Empty string won't throw on py2
        https_pool.ca_certs = "/no_valid_path_to_ca_certs"

        self.assertRaises(SSLError, https_pool.request, "GET", "/")
开发者ID:gagern,项目名称:urllib3,代码行数:7,代码来源:test_https.py


示例12: request

 def request():
     try:
         pool = HTTPSConnectionPool(self.host, self.port, assert_fingerprint=fingerprint)
         response = pool.urlopen("GET", "/", preload_content=False, timeout=Timeout(connect=1, read=0.001))
         response.read()
     finally:
         pool.close()
开发者ID:boyxuper,项目名称:urllib3,代码行数:7,代码来源:test_socketlevel.py


示例13: test_can_validate_ip_san

 def test_can_validate_ip_san(self):
     """Ensure that urllib3 can validate SANs with IP addresses in them."""
     https_pool = HTTPSConnectionPool('127.0.0.1', self.port,
                                      cert_reqs='CERT_REQUIRED',
                                      ca_certs=DEFAULT_CA)
     r = https_pool.request('GET', '/')
     self.assertEqual(r.status, 200)
开发者ID:fredthomsen,项目名称:urllib3,代码行数:7,代码来源:test_https.py


示例14: TestHTTPS_TLSv1

class TestHTTPS_TLSv1(HTTPSDummyServerTestCase):
    certs = DEFAULT_CERTS.copy()
    certs['ssl_version'] = ssl.PROTOCOL_TLSv1

    def setUp(self):
        self._pool = HTTPSConnectionPool(self.host, self.port)

    def test_set_ssl_version_to_sslv3(self):
        self._pool.ssl_version = ssl.PROTOCOL_SSLv3
        self.assertRaises(SSLError, self._pool.request, 'GET', '/')

    def test_ssl_version_as_string(self):
        self._pool.ssl_version = 'PROTOCOL_SSLv3'
        self.assertRaises(SSLError, self._pool.request, 'GET', '/')

    def test_ssl_version_as_short_string(self):
        self._pool.ssl_version = 'SSLv3'
        self.assertRaises(SSLError, self._pool.request, 'GET', '/')

    def test_discards_connection_on_sslerror(self):
        self._pool.cert_reqs = 'CERT_REQUIRED'
        self.assertRaises(SSLError, self._pool.request, 'GET', '/')
        self._pool.ca_certs = DEFAULT_CA
        self._pool.request('GET', '/')

    def test_set_cert_default_cert_required(self):
        conn = VerifiedHTTPSConnection(self.host, self.port)
        conn.set_cert(ca_certs=DEFAULT_CA)
        self.assertEqual(conn.cert_reqs, 'CERT_REQUIRED')
开发者ID:JioCloudVPC,项目名称:urllib3,代码行数:29,代码来源:test_https.py


示例15: test_verify_none_and_bad_fingerprint

    def test_verify_none_and_bad_fingerprint(self):
        https_pool = HTTPSConnectionPool('127.0.0.1', self.port,
                                         cert_reqs='CERT_NONE',
                                         ca_certs=DEFAULT_CA_BAD)

        https_pool.assert_fingerprint = 'AA:AA:AA:AA:AA:AAAA:AA:AAAA:AA:' \
                                        'AA:AA:AA:AA:AA:AA:AA:AA:AA'
        self.assertRaises(SSLError, https_pool.request, 'GET', '/')
开发者ID:JasonRepo,项目名称:urllib3,代码行数:8,代码来源:test_https.py


示例16: test_source_address_error

 def test_source_address_error(self):
     for addr in INVALID_SOURCE_ADDRESSES:
         https_pool = HTTPSConnectionPool(
             self.host, self.port, cert_reqs='CERT_REQUIRED',
             source_address=addr)
         https_pool.ca_certs = DEFAULT_CA
         self.assertRaises(
             MaxRetryError, https_pool.request, 'GET', '/source_address')
开发者ID:iyed,项目名称:urllib3,代码行数:8,代码来源:test_https.py


示例17: test_good_fingerprint_and_hostname_mismatch

    def test_good_fingerprint_and_hostname_mismatch(self):
        https_pool = HTTPSConnectionPool('127.0.0.1', self.port,
                                         cert_reqs='CERT_REQUIRED',
                                         ca_certs=DEFAULT_CA)

        https_pool.assert_fingerprint = '92:81:FE:85:F7:0C:26:60:EC:D6:B3:' \
                                        'BF:93:CF:F9:71:CC:07:7D:0A'
        https_pool.request('GET', '/')
开发者ID:JioCloudVPC,项目名称:urllib3,代码行数:8,代码来源:test_https.py


示例18: test_verify_none_and_good_fingerprint

    def test_verify_none_and_good_fingerprint(self):
        https_pool = HTTPSConnectionPool('127.0.0.1', self.port,
                                         cert_reqs='CERT_NONE',
                                         ca_certs=DEFAULT_CA_BAD)

        https_pool.assert_fingerprint = '92:81:FE:85:F7:0C:26:60:EC:D6:B3:' \
                                        'BF:93:CF:F9:71:CC:07:7D:0A'
        https_pool.request('GET', '/')
开发者ID:JioCloudVPC,项目名称:urllib3,代码行数:8,代码来源:test_https.py


示例19: test_assert_fingerprint_sha1

    def test_assert_fingerprint_sha1(self):
        https_pool = HTTPSConnectionPool('localhost', self.port,
                                         cert_reqs='CERT_REQUIRED',
                                         ca_certs=DEFAULT_CA)

        https_pool.assert_fingerprint = '92:81:FE:85:F7:0C:26:60:EC:D6:B3:' \
                                        'BF:93:CF:F9:71:CC:07:7D:0A'
        https_pool.request('GET', '/')
开发者ID:JioCloudVPC,项目名称:urllib3,代码行数:8,代码来源:test_https.py


示例20: test_assert_specific_hostname

    def test_assert_specific_hostname(self):
        https_pool = HTTPSConnectionPool('localhost', self.port,
                                         cert_reqs='CERT_REQUIRED',
                                         ca_certs=DEFAULT_CA)
        self.addCleanup(https_pool.close)

        https_pool.assert_hostname = 'localhost'
        https_pool.request('GET', '/')
开发者ID:Lukasa,项目名称:urllib3,代码行数:8,代码来源:test_https.py



注:本文中的urllib3.HTTPSConnectionPool类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python connectionpool.connection_from_url函数代码示例发布时间:2022-05-27
下一篇:
Python urllib3.HTTPConnectionPool类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap