speasy.core.http module

class speasy.core.http.Response(response: BaseHTTPResponse)[source]

Bases: object

property bytes
property headers
json()[source]
property ok
property status_code
property text
property url
speasy.core.http.auth_header(url: str) Dict[str, str][source]

Generate authentication headers for a given URL.

This function processes a URL to extract its hostname and generates authentication headers based on the hostname. It uses auxiliary functions to determine the hostname and retrieve the authentication details. The authentication credentials are read from the user’s .netrc file.

Args:

url (str): The URL for which to generate authentication headers.

Returns:

Dict[str, str]: A dictionary containing the authentication headers corresponding to the provided URL.

Raises:

None

speasy.core.http.is_server_up(url: str | None = None, host: str | None = None, port: int | None = None, timeout: int = 5, retries=5) bool[source]

Checks if a server is up and running. If url is provided, host and port are ignored.

Parameters:
urlOptional[str]

url to check (scheme://host[:port]), if provided host and port are ignored

hostOptional[str]

host to check, if provided port must be provided as well

portOptional[int]

port to check, if provided host must be provided as well

timeoutint

timeout in seconds

retriesint

number of retries

Returns:
bool

True if server is up and running, False otherwise

Raises:
ValueError

If neither url nor host and port are provided

speasy.core.http.urlopen(url, timeout: int = 60, headers: dict = None) Response[source]