本文整理汇总了Python中urllib3.exceptions.LocationParseError方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.LocationParseError方法的具体用法?Python exceptions.LocationParseError怎么用?Python exceptions.LocationParseError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类urllib3.exceptions
的用法示例。
在下文中一共展示了exceptions.LocationParseError方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from urllib3 import exceptions [as 别名]
# 或者: from urllib3.exceptions import LocationParseError [as 别名]
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
示例2: __init__
# 需要导入模块: from urllib3 import exceptions [as 别名]
# 或者: from urllib3.exceptions import LocationParseError [as 别名]
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
示例3: get_schema_and_host
# 需要导入模块: from urllib3 import exceptions [as 别名]
# 或者: from urllib3.exceptions import LocationParseError [as 别名]
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
示例4: crawl
# 需要导入模块: from urllib3 import exceptions [as 别名]
# 或者: from urllib3.exceptions import LocationParseError [as 别名]
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
示例5: test_wrong_host_format
# 需要导入模块: from urllib3 import exceptions [as 别名]
# 或者: from urllib3.exceptions import LocationParseError [as 别名]
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)