requests.exceptions.InvalidSchema

Here are the examples of the python api requests.exceptions.InvalidSchema taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

7 Examples 7

Example 1

Project: scalyr-agent-2
Source File: client.py
View license
    def get_adapter(self, url):
        try:
            return super(Client, self).get_adapter(url)
        except requests.exceptions.InvalidSchema as e:
            if self._custom_adapter:
                return self._custom_adapter
            else:
                raise e

Example 2

Project: scalyr-agent-2
Source File: client.py
View license
    def get_adapter(self, url):
        try:
            return super(Client, self).get_adapter(url)
        except requests.exceptions.InvalidSchema as e:
            if self._custom_adapter:
                return self._custom_adapter
            else:
                raise e

Example 3

Project: pywikibot-core
Source File: http_tests.py
View license
    def test_invalid_scheme(self):
        """Test invalid scheme."""
        # A InvalidSchema is raised within requests
        self.assertRaises(requests.exceptions.InvalidSchema,
                          http.fetch,
                          uri='invalid://url')

Example 4

Project: docker-py
Source File: client.py
View license
    def get_adapter(self, url):
        try:
            return super(Client, self).get_adapter(url)
        except requests.exceptions.InvalidSchema as e:
            if self._custom_adapter:
                return self._custom_adapter
            else:
                raise e

Example 5

Project: docker-py
Source File: client.py
View license
    def get_adapter(self, url):
        try:
            return super(Client, self).get_adapter(url)
        except requests.exceptions.InvalidSchema as e:
            if self._custom_adapter:
                return self._custom_adapter
            else:
                raise e

Example 6

Project: cslbot
Source File: urlutils.py
View license
def get_title(url):
    title = None
    timeout = (5, 20)
    with closing(Session()) as session:
        # User-Agent is really hard to get right :(
        session.headers.update({'User-Agent': 'Mozilla/5.0 CslBot'})
        try:
            req = session.head(url, allow_redirects=True, verify=False, timeout=timeout)
            if req.status_code == codes.ok:
                title = parse_mime(req)
            # 405 means this site doesn't support HEAD
            elif req.status_code != codes.not_allowed:
                title = 'HTTP Error %d: %s' % (req.status_code, req.reason)
        except exceptions.InvalidSchema:
            raise CommandFailedException('%s is not a supported url.' % url)
        except exceptions.MissingSchema:
            return get_title('http://%s' % url)
        # HEAD didn't work, so try GET
        if title is None:
            req = session.get(url, timeout=timeout, stream=True)
            if req.status_code == codes.ok:
                title = parse_mime(req) or parse_title(req)
            else:
                title = 'HTTP Error %d: %s' % (req.status_code, req.reason)
    if title is None:
        return 'Title Not Found'
    # We don't want overly-long titles.
    return misc.truncate_msg(title, 256)

Example 7

Project: syntribos
Source File: test_http_checks.py
View license
    def test_invalid_schema(self):
        signal = http_checks.check_fail(rex.InvalidSchema())
        self._assert_has_tags(self.bad_request_tags, signal)
        self._assert_has_slug("HTTP_FAIL_INVALID_SCHEMA", signal)