usp.web_client.requests_client¶
Implementation of usp.web_client.abstract_client with Requests.
- class usp.web_client.requests_client.RequestsWebClient¶
Bases:
AbstractWebClientrequests-based web client to be used by the sitemap fetcher.
- __init__(verify=True, wait: float | None = None, random_wait: bool = False)¶
- Parameters:
verify – whether certificates should be verified for HTTPS requests.
wait – time to wait between requests, in seconds.
random_wait – if true, wait time is multiplied by a random number between 0.5 and 1.5.
- get(url: str) AbstractWebClientResponse¶
Fetch a URL and return a response.
Method shouldn’t throw exceptions on connection errors (including timeouts); instead, such errors should be reported via Response object.
- Parameters:
url – URL to fetch.
- Returns:
Response object.
- set_max_response_data_length(max_response_data_length: int) None¶
Set the maximum number of bytes that the web client will fetch.
- Parameters:
max_response_data_length – Maximum number of bytes that the web client will fetch, or None to fetch all.
- class usp.web_client.requests_client.RequestsWebClientErrorResponse¶
Bases:
WebClientErrorResponseError response from the Requests parser.
- __init__(message: str, retryable: bool)¶
Constructor.
- Parameters:
message – Message describing what went wrong.
retryable – True if the request should be retried.
- class usp.web_client.requests_client.RequestsWebClientSuccessResponse¶
Bases:
AbstractWebClientSuccessResponserequests-based successful response.
- __init__(requests_response: Response, max_response_data_length: int | None = None)¶
- Parameters:
requests_response – Response data
max_response_data_length – Maximum data length, or
Noneto not restrict.
- header(case_insensitive_name: str) str | None¶
Return HTTP header value for a given case-insensitive name, or None if such header wasn’t set.
- Parameters:
case_insensitive_name – HTTP header’s name, e.g. “Content-Type”.
- Returns:
HTTP header’s value, or None if it was unset.
- raw_data() bytes¶
Return encoded raw data of the response.
- Returns:
Encoded raw data of the response.