generic requests#
Implement generic request function with own logging and return functionality
- class src.tetue_generic.generic_requests.GenReqConfiguration(**data)[source]#
Configuration settings for generic HTTP requests.
This class inherits from Pydantic’s BaseModel and defines the configuration parameters for making generic HTTP requests.
- request_timeout#
The timeout duration for HTTP requests in seconds. Must be a positive integer.
- Type:
PositiveInt
Note
The use of PositiveInt ensures that the timeout value is always a positive integer, providing a safeguard against invalid timeout settings.
- async src.tetue_generic.generic_requests.generic_http_request(url, header, config)[source]#
Performs an asynchronous HTTP GET request and handles potential exceptions.
This function sends a GET request to the specified URL with given headers and timeout. It catches and logs common HTTP request exceptions using Loguru.
- Parameters:
url (str) – The URL to send the GET request to.
header (dict) – A dictionary of HTTP headers to include in the request.
config (pydantic.BaseModel) – Configuration object containing request settings,
- Returns:
The response object if the request is successful, or None if an exception occurs.
- Return type:
requests.Response | None
- Raises:
No exceptions are raised; they are caught and logged instead. –
- Logs:
HTTP errors
Connection timeout errors
General connection errors
Note
This function uses a global logger object for logging, which should be a configured Loguru logger instance.