Http¶
flowtask.interfaces.http
¶
HTTPService
¶
Bases: CredentialsInterface, PandasDataframe
HTTPService.
Overview
Interface for making connections to HTTP services.
api_get
async
¶
api_get(url, cookies=None, params=None, headers=None, use_proxy=None, free_proxy=False, use_http2=True)
Make an asynchronous HTTP GET request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The URL to send the GET request to. |
required |
cookies
|
Cookies
|
Cookies to include in the request. |
None
|
params
|
dict
|
Dictionary of query parameters to include in the URL. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Dict[str, Any]
|
The JSON response from the API if the request is successful. |
Dict[str, Any]
|
Returns an empty dictionary if the request fails. |
async_request
async
¶
Asynchronously sends an HTTP request using aiohttp.
:param url: The URL to send the request to. :param method: The HTTP method to use (e.g., 'GET', 'POST'). :param data: The data to send in the request body. :param use_json: Whether to send the data as JSON. :param use_proxy: force proxy usage. :return: A tuple containing the result and any error information.
build_url
¶
Constructs a full URL with optional query parameters and arguments.
:param url: The base URL to be formatted. :param queryparams: Additional query parameters to be appended to the URL. :param args: Arguments to format within the URL. :return: The fully constructed URL.
evaluate_error
async
¶
evaluate_response.
Check Response status and available payloads. Args: response (type): description url (str): description
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
tuple
|
description |
get_proxies
async
¶
Asynchronously retrieves a list of free proxies. TODO: SELECT or rotate the free/paid proxies.
process_request
async
¶
Processes the result of an asynchronous HTTP request.
:param future: The future object representing the asynchronous operation. :param url: The URL that was requested. :return: A tuple containing the result and any error information.
process_response
async
¶
Processes the response from an HTTP request.
:param response: The response object from aiohttp. :param url: The URL that was requested. :return: A tuple containing the processed result and any error information.
refresh_proxies
async
¶
Asynchronously refreshes the list of proxies if proxy usage is enabled.
request
async
¶
Sends an HTTP request using the requests library.
:param url: The URL to send the request to. :param method: The HTTP method to use (e.g., 'GET', 'POST'). :param data: The data to send in the request body. :return: A tuple containing the result and any error information.
session
async
¶
session(url, method='get', data=None, cookies=None, headers=None, use_json=False, follow_redirects=False, use_proxy=False, accept=None, return_response=False)
Asynchronously sends an HTTP request using HTTPx.
:param url: The URL to send the request to. :param method: The HTTP method to use (e.g., 'GET', 'POST'). :param data: The data to send in the request body. :param use_json: Whether to send the data as JSON. :param cookies: A dictionary of cookies to send with the request. :param headers: A dictionary of headers to send with the request. :return: A tuple containing the result and any error information.
bad_gateway_exception
¶
Check if the exception is a 502 Bad Gateway error.