Python urllib3.exceptions.LocationParseError() Examples

The following are 5 code examples of urllib3.exceptions.LocationParseError(). 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.exceptions , or try the search function .
Example #1
Source File: api.py    From matrixcli with GNU General Public License v3.0 6 votes vote down vote up
def __init__(
            self, base_url, token=None, identity=None,
            default_429_wait_ms=5000,
            use_authorization_header=True,
            connection_timeout=60
    ):
        try:
            scheme, auth, host, port, path, query, fragment = parse_url(base_url)
        except LocationParseError:
            raise MatrixError("Invalid homeserver url %s" % base_url)
        if not scheme:
            raise MatrixError("No scheme in homeserver url %s" % base_url)
        self._base_url = base_url

        self.token = token
        self.identity = identity
        self.txn_id = 0
        self.validate_cert = True
        self.session = Session()
        self.default_429_wait_ms = default_429_wait_ms
        self.use_authorization_header = use_authorization_header
        self.connection_timeout = connection_timeout 
Example #2
Source File: api.py    From matrix-python-sdk with Apache License 2.0 6 votes vote down vote up
def __init__(
            self, base_url, token=None, identity=None,
            default_429_wait_ms=5000,
            use_authorization_header=True
    ):
        try:
            scheme, auth, host, port, path, query, fragment = parse_url(base_url)
        except LocationParseError:
            raise MatrixError("Invalid homeserver url %s" % base_url)
        if not scheme:
            raise MatrixError("No scheme in homeserver url %s" % base_url)
        self._base_url = base_url

        self.token = token
        self.identity = identity
        self.txn_id = 0
        self.validate_cert = True
        self.session = Session()
        self.default_429_wait_ms = default_429_wait_ms
        self.use_authorization_header = use_authorization_header 
Example #3
Source File: ti_provider_base.py    From msticpy with MIT License 5 votes vote down vote up
def get_schema_and_host(
    url: str, require_url_encoding: bool = False
) -> Tuple[Optional[str], Optional[str], Optional[str]]:
    """
    Return URL scheme and host and cleaned URL.

    Parameters
    ----------
    url : str
        Input URL
    require_url_encoding : bool
        Set to True if url needs encoding. Defualt is False.

    Returns
    -------
    Tuple[Optional[str], Optional[str], Optional[str]
        Tuple of URL, scheme, host

    """
    clean_url = None
    scheme = None
    host = None
    try:
        scheme, _, host, _, _, _, _ = parse_url(url)
        clean_url = url
    except LocationParseError:
        # Try to clean URL and re-check
        cleaned_url = _clean_url(url)
        if cleaned_url is not None:
            try:
                scheme, _, host, _, _, _, _ = parse_url(cleaned_url)
                clean_url = cleaned_url
            except LocationParseError:
                pass
    if require_url_encoding and clean_url:
        clean_url = quote_plus(clean_url)
    return clean_url, scheme, host 
Example #4
Source File: noisy.py    From noisy with GNU General Public License v3.0 5 votes vote down vote up
def crawl(self):
        """
        Collects links from our root urls, stores them and then calls
        `_browse_from_links` to browse them
        """
        self._start_time = datetime.datetime.now()

        while True:
            url = random.choice(self._config["root_urls"])
            try:
                body = self._request(url).content
                self._links = self._extract_urls(body, url)
                logging.debug("found {} links".format(len(self._links)))
                self._browse_from_links()

            except requests.exceptions.RequestException:
                logging.warn("Error connecting to root url: {}".format(url))
                
            except MemoryError:
                logging.warn("Error: content at url: {} is exhausting the memory".format(url))

            except LocationParseError:
                logging.warn("Error encountered during parsing of: {}".format(url))

            except self.CrawlerTimedOut:
                logging.info("Timeout has exceeded, exiting")
                return 
Example #5
Source File: test_integration.py    From crash with Apache License 2.0 5 votes vote down vote up
def test_wrong_host_format(self):
        parser = get_parser()
        args = parser.parse_args([
            "--hosts", "localhost:12AB"
        ])

        crate_hosts = [host_and_port(h) for h in args.hosts]

        with self.assertRaises(LocationParseError):
            _create_shell(crate_hosts, False, None, False, args)