How to use the urllib3.util function in urllib3

To help you get started, we’ve selected a few urllib3 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ARMmbed / mbed-cloud-sdk-python / src / mbed_cloud / _backends / device_directory / configuration.py View on Github external
def get_basic_auth_token(self):
        """Gets HTTP basic authentication header (string).

        :return: The token for basic HTTP authentication.
        """
        return urllib3.util.make_headers(basic_auth=self.username + ':' + self.password)\
                           .get('authorization')
github xbmc / addon-check / kodi_addon_checker / check_url.py View on Github external
sources = parsed_xml.findall("./extension[@point='kodi.addon.metadata']/forum")
    sources += parsed_xml.findall("./extension[@point='xbmc.addon.metadata']/forum")

    sources += parsed_xml.findall("./extension[@point='kodi.addon.metadata']/source")
    sources += parsed_xml.findall("./extension[@point='xbmc.addon.metadata']/source")

    sources += parsed_xml.findall("./extension[@point='kodi.addon.metadata']/website")
    sources += parsed_xml.findall("./extension[@point='xbmc.addon.metadata']/website")

    for source in sources:
        if not source.text:
            continue

        url = source.text
        scheme = True
        if urllib3.util.parse_url(source.text).scheme is None:
            url = "http://{}".format(source.text)
            scheme = False

        try:
            r = requests.head(url, allow_redirects=True, timeout=5)
            host = urllib3.util.parse_url(r.url).host
            if not scheme and not host.endswith(source.text):
                report.add(Record(WARNING, "{} redirects to {}".format(source.text, host)))
            elif scheme and r.url.rstrip('/') != url.rstrip('/'):
                report.add(Record(WARNING, "{} redirects to {}".format(source.text, r.url)))
            r.raise_for_status()
        except (requests.exceptions.ConnectionError, requests.exceptions.ConnectTimeout, requests.exceptions.HTTPError,
                requests.exceptions.MissingSchema, requests.exceptions.ReadTimeout, requests.exceptions.SSLError) as e:
            report.add(Record(WARNING, e))
github ARMmbed / mbed-cloud-sdk-python / src / mbed_cloud / _backends / statistics / configuration.py View on Github external
def get_basic_auth_token(self):
        """Gets HTTP basic authentication header (string).

        :return: The token for basic HTTP authentication.
        """
        return urllib3.util.make_headers(basic_auth=self.username + ':' + self.password)\
                           .get('authorization')
github PyGithub / PyGithub / github / MainClass.py View on Github external
assert isinstance(base_url, (str, six.text_type)), base_url
        assert isinstance(timeout, six.integer_types), timeout
        assert client_id is None or isinstance(
            client_id, (str, six.text_type)
        ), client_id
        assert client_secret is None or isinstance(
            client_secret, (str, six.text_type)
        ), client_secret
        assert user_agent is None or isinstance(
            user_agent, (str, six.text_type)
        ), user_agent
        assert isinstance(api_preview, (bool))
        assert (
            retry is None
            or isinstance(retry, (int))
            or isinstance(retry, (urllib3.util.Retry))
        )
        self.__requester = Requester(
            login_or_token,
            password,
            jwt,
            base_url,
            timeout,
            client_id,
            client_secret,
            user_agent,
            per_page,
            api_preview,
            verify,
            retry,
        )
github ARMmbed / mbed-cloud-sdk-python / mbed_cloud / _backends / developer_certificate / configuration.py View on Github external
def get_basic_auth_token(self):
        """
        Gets HTTP basic authentication header (string).

        :return: The token for basic HTTP authentication.
        """
        return urllib3.util.make_headers(basic_auth=self.username + ':' + self.password)\
                           .get('authorization')
github wavefrontHQ / python-client / wavefront_api_client / configuration.py View on Github external
def get_basic_auth_token(self):
        """Gets HTTP basic authentication header (string).

        :return: The token for basic HTTP authentication.
        """
        return urllib3.util.make_headers(
            basic_auth=self.username + ':' + self.password
        ).get('authorization')
github Azure / azure-cli / src / command_modules / azure-cli-appservice / azure / cli / command_modules / appservice / custom.py View on Github external
def _ping_scm_site(cmd, resource_group, name):
    from azure.cli.core.util import should_disable_connection_verify

    #  wake up kudu, by making an SCM call
    import requests
    #  work around until the timeout limits issue for linux is investigated & fixed
    user_name, password = _get_site_credential(cmd.cli_ctx, resource_group, name)
    scm_url = _get_scm_url(cmd, resource_group, name)
    import urllib3
    authorization = urllib3.util.make_headers(basic_auth='{}:{}'.format(user_name, password))
    requests.get(scm_url + '/api/settings', headers=authorization, verify=not should_disable_connection_verify())
github intrinio / python-sdk / intrinio_sdk / configuration.py View on Github external
def get_basic_auth_token(self):
        """Gets HTTP basic authentication header (string).

        :return: The token for basic HTTP authentication.
        """
        return urllib3.util.make_headers(
            basic_auth=self.username + ':' + self.password
        ).get('authorization')
github OpenAPITools / openapi-generator / samples / client / petstore / python / petstore_api / configuration.py View on Github external
def get_basic_auth_token(self):
        """Gets HTTP basic authentication header (string).

        :return: The token for basic HTTP authentication.
        """
        return urllib3.util.make_headers(
            basic_auth=self.username + ':' + self.password
        ).get('authorization')
github scVENUS / PeekabooAV / peekaboo / toolbox / cuckoo.py View on Github external
self.__sample = sample
        self.__submission_time = datetime.datetime.utcnow()

    def is_older_than(self, seconds):
        """ Returns True if the difference between submission time and now,
        i.e. the age of the job, is larger than given number of seconds. """
        max_age = datetime.timedelta(seconds=seconds)
        return datetime.datetime.utcnow() - self.__submission_time > max_age

    @property
    def sample(self):
        """ Returns the sample the job is analyzing. """
        return self.__sample


class WhitelistRetry(urllib3.util.retry.Retry):
    """ A Retry class which has a status code whitelist, allowing to retry all
    requests not whitelisted in a hard-core, catch-all manner. """
    def __init__(self, status_whitelist=None, abort=None, **kwargs):
        super().__init__(**kwargs)
        self.status_whitelist = status_whitelist or set()
        # Event that is set if we're not to retry
        self.abort = abort

    def new(self, **kwargs):
        """ Adjusted shallow copy method to carry our parameters over into our
        copy. """
        if 'status_whitelist' not in kwargs:
            kwargs['status_whitelist'] = self.status_whitelist
        if 'abort' not in kwargs:
            kwargs['abort'] = self.abort
        return super().new(**kwargs)