fftools.web¶
- fftools.web.dig(fqdn: str, record_type: str) list[str][source]¶
Resolve dns record.
- Parameters:
- Raises:
ValueError – if no answer was found.
exc – on resolving errors.
- Returns:
A a list of resolved addresses.
- Return type:
- fftools.web.download_file(url: str, download_path: Path, timeout: int = 30, follow_redirects: bool = True, chunk_size: int | None = 65536, username: str | None = None, password: str | None = None, **kwargs) None[source]¶
Download a file with httpx.stream.
- Parameters:
url (str) – url of the file.
download_path (Path) – ath to save the file to.
timeout (int) – timeout of the request in seconds.
follow_redirects (bool) – follow HTTP 3XX redirects. None sets it to the server response default.
chunk_size (int | None) – size of the chunks which are downloaded.
username (str | None) – username for basic auth. if unset no authentication is used.
password (str | None) – password for basic auth. if unset no authentication is used.
kwargs – other kwargs directly supplied to httpx.request
- Raises:
ValueError – if requested file size is 0 bytes.
exc – on download errors.
- Return type:
None
- fftools.web.req(method: Literal['GET', 'POST', 'HEAD', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'], url: str, timeout: float = 5, default_headers: bool = True, follow_redirects: bool = True, payload: dict[str, Any] | str | bytes | None = None, username: str | None = None, password: str | None = None, **kwargs) Response[source]¶
Make a http(s) request.
- Parameters:
method (Literal['GET', 'POST', 'HEAD', 'PUT', 'DELETE', 'PATCH', 'OPTIONS']) – HTTP method, e.g. GET.
url (str) – url for the request.
timeout (float) – timeout of the request in seconds.
default_headers (bool) – send default headers for content-type and accept.
follow_redirects (bool) – follow HTTP 3XX redirects.
payload (dict[str, Any] | str | bytes | None) – data to send. either dict, str or bytes.
username (str | None) – username for basic auth. if unset no authentication is used.
password (str | None) – password for basic auth. if unset no authentication is used.
kwargs – other kwargs directly supplied to httpx.request
- Raises:
exc – on request errors.
- Returns:
A httpx.Response object
- Return type:
Response
- fftools.web.upload_file(method: Literal['POST', 'PUT', 'PATCH'], url: str, file_path: Path, timeout: int = 30, username: str | None = None, password: str | None = None, **kwargs) Response[source]¶
Upload a file with httpx.
- Parameters:
method (Literal['POST', 'PUT', 'PATCH']) – http method to use for the upload.
url (str) – upload url.
file_path (Path) – path of file to upload.
timeout (int) – timeout of the request in seconds.
username (str | None) – username for basic auth. if unset no authentication is used.
password (str | None) – password for basic auth. if unset no authentication is used.
kwargs – other kwargs directly supplied to httpx.request
- Raises:
exc – on upload errors.
- Returns:
A httpx.Response object.
- Return type:
Response