Python urllib3.proxy_from_url() Examples

The following are 8 code examples of urllib3.proxy_from_url(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module urllib3 , or try the search function .
Example #1
Source File: httpsession.py    From deepWordBug with Apache License 2.0 5 votes vote down vote up
def _get_proxy_manager(self, proxy_url):
        if proxy_url not in self._proxy_managers:
            proxy_headers = self._proxy_config.proxy_headers_for(proxy_url)
            proxy_manager_kwargs = self._get_pool_manager_kwargs(
                proxy_headers=proxy_headers)
            proxy_manager = proxy_from_url(proxy_url, **proxy_manager_kwargs)
            proxy_manager.pool_classes_by_scheme = self._pool_classes_by_scheme
            self._proxy_managers[proxy_url] = proxy_manager

        return self._proxy_managers[proxy_url] 
Example #2
Source File: httpsession.py    From bash-lambda-layer with MIT License 5 votes vote down vote up
def _get_proxy_manager(self, proxy_url):
        if proxy_url not in self._proxy_managers:
            proxy_headers = self._proxy_config.proxy_headers_for(proxy_url)
            proxy_manager_kwargs = self._get_pool_manager_kwargs(
                proxy_headers=proxy_headers)
            proxy_manager = proxy_from_url(proxy_url, **proxy_manager_kwargs)
            proxy_manager.pool_classes_by_scheme = self._pool_classes_by_scheme
            self._proxy_managers[proxy_url] = proxy_manager

        return self._proxy_managers[proxy_url] 
Example #3
Source File: httpsession.py    From AWS-Transit-Gateway-Demo-MultiAccount with MIT License 5 votes vote down vote up
def _get_proxy_manager(self, proxy_url):
        if proxy_url not in self._proxy_managers:
            proxy_headers = self._proxy_config.proxy_headers_for(proxy_url)
            proxy_manager_kwargs = self._get_pool_manager_kwargs(
                proxy_headers=proxy_headers)
            proxy_manager = proxy_from_url(proxy_url, **proxy_manager_kwargs)
            proxy_manager.pool_classes_by_scheme = self._pool_classes_by_scheme
            self._proxy_managers[proxy_url] = proxy_manager

        return self._proxy_managers[proxy_url] 
Example #4
Source File: httpsession.py    From AWS-Transit-Gateway-Demo-MultiAccount with MIT License 5 votes vote down vote up
def _get_proxy_manager(self, proxy_url):
        if proxy_url not in self._proxy_managers:
            proxy_headers = self._proxy_config.proxy_headers_for(proxy_url)
            proxy_manager_kwargs = self._get_pool_manager_kwargs(
                proxy_headers=proxy_headers)
            proxy_manager = proxy_from_url(proxy_url, **proxy_manager_kwargs)
            proxy_manager.pool_classes_by_scheme = self._pool_classes_by_scheme
            self._proxy_managers[proxy_url] = proxy_manager

        return self._proxy_managers[proxy_url] 
Example #5
Source File: ph2.py    From py-parsehub with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def __init__(self, api_key: str, proxy: str=None):
        """
        Initializes ParseHub objects

        :param api_key: your API key from either PH website or browser plugin
        :param proxy: if needed, in format http[s]://host:port
        """
        self.api_key = api_key
        if proxy:
            self.conn = urllib3.proxy_from_url(proxy)
        else:
            self.conn = urllib3.PoolManager()
        self.projects = [project for project in self.getprojects()] 
Example #6
Source File: httpsession.py    From aws-builders-fair-projects with Apache License 2.0 5 votes vote down vote up
def _get_proxy_manager(self, proxy_url):
        if proxy_url not in self._proxy_managers:
            proxy_headers = self._proxy_config.proxy_headers_for(proxy_url)
            proxy_manager_kwargs = self._get_pool_manager_kwargs(
                proxy_headers=proxy_headers)
            proxy_manager = proxy_from_url(proxy_url, **proxy_manager_kwargs)
            proxy_manager.pool_classes_by_scheme = self._pool_classes_by_scheme
            self._proxy_managers[proxy_url] = proxy_manager

        return self._proxy_managers[proxy_url] 
Example #7
Source File: test_bad_urllib3_kwarg_use.py    From dlint with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def test_bad_urllib3_kwarg_usage(self):
        python_node = self.get_ast_node(
            """
            import urllib3
            import ssl
            from ssl import CERT_NONE

            urllib3.PoolManager(cert_reqs="CERT_NONE")
            urllib3.ProxyManager(cert_reqs="CERT_NONE")
            urllib3.HTTPSConnectionPool(cert_reqs="NONE")
            urllib3.connection_from_url(cert_reqs=ssl.CERT_NONE)
            urllib3.proxy_from_url(cert_reqs=CERT_NONE)
            """
        )

        linter = dlint.linters.BadUrllib3KwargUseLinter()
        linter.visit(python_node)

        result = linter.get_results()
        expected = [
            dlint.linters.base.Flake8Result(
                lineno=6,
                col_offset=0,
                message=dlint.linters.BadUrllib3KwargUseLinter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=7,
                col_offset=0,
                message=dlint.linters.BadUrllib3KwargUseLinter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=8,
                col_offset=0,
                message=dlint.linters.BadUrllib3KwargUseLinter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=9,
                col_offset=0,
                message=dlint.linters.BadUrllib3KwargUseLinter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=10,
                col_offset=0,
                message=dlint.linters.BadUrllib3KwargUseLinter._error_tmpl
            ),
        ]

        assert result == expected 
Example #8
Source File: rest.py    From aws-kube-codesuite with Apache License 2.0 4 votes vote down vote up
def __init__(self, pools_size=4, config=configuration):
        # urllib3.PoolManager will pass all kw parameters to connectionpool
        # https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/poolmanager.py#L75
        # https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/connectionpool.py#L680
        # ca_certs vs cert_file vs key_file
        # http://stackoverflow.com/a/23957365/2985775

        # cert_reqs
        if config.verify_ssl:
            cert_reqs = ssl.CERT_REQUIRED
        else:
            cert_reqs = ssl.CERT_NONE

        # ca_certs
        if config.ssl_ca_cert:
            ca_certs = config.ssl_ca_cert
        else:
            # if not set certificate file, use Mozilla's root certificates.
            ca_certs = certifi.where()

        # cert_file
        cert_file = config.cert_file

        # key file
        key_file = config.key_file

        kwargs = {
            'num_pools': pools_size,
            'cert_reqs': cert_reqs,
            'ca_certs': ca_certs,
            'cert_file': cert_file,
            'key_file': key_file,
        }

        if config.connection_pool_maxsize is not None:
            kwargs['maxsize'] = config.connection_pool_maxsize

        if config.assert_hostname is not None:
            kwargs['assert_hostname'] = config.assert_hostname

        # https pool manager
        if config.http_proxy_url is not None:
            self.pool_manager = urllib3.proxy_from_url(
                config.http_proxy_url, **kwargs
            )
        else:
            self.pool_manager = urllib3.PoolManager(
	        **kwargs
            )