
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
A robust Python library for making resilient HTTP requests with retries, proxies, and custom headers.
resilient_requester
is a lightweight Python package designed to simplify and improve HTTP GET requests
by incorporating features such as retries, proxies, customizable headers, and timeout management.
It is built to handle network errors gracefully and provide informative logging for debugging and monitoring.
Resilient HTTP Requests
: Automatically retries failed requests with configurable retry limits and randomized wait times.
Proxy Support
: Easily integrate proxies for requests.
Customizable Headers
: Generate random user-agent headers or when not provided by user.
Timeout Management
: Enforce minimum timeout values to prevent overly aggressive requests.
Informative Logging
: Detailed logging for request attempts, failures, and retries.
Type Checking
: Ensures correct parameter types to prevent runtime errors.
Lightweight and Simple
: Minimal dependencies and easy-to-use interface.
You can install resilient_requester
using pip:
pip install resilient_requester
Here’s a simple example to get started with resilient_requester
:
ffrom resilient_requester import get_request
response = get_request("https://example.com")
if response:
print(f"Status Code: {response.status_code}")
print(response.text)
else:
print("Request failed after retries.")
You can specify a proxy dictionary to route requests through a proxy server.
from resilient_requester import get_request
proxy = {
"http": "http://proxy.example.com:8080",
"https": "https://proxy.example.com:8080"
}
response = get_request(
url="https://example.com",
proxy=proxy
)
if response:
print("Request successful through proxy!")
Send a request with custom headers, a specific timeout, and multiple retries.
from resilient_requester import get_request
custom_headers = {
"User-Agent": "MyCustomAgent/1.0",
"Accept": "application/json"
}
response = get_request(
url="https://api.example.com/data",
headers=custom_headers,
timeout=10,
retries=3
)
if response:
print(f"Request successful: {response.status_code}")
print(response.json())
else:
print("Request failed after retries.")
You can configure the timeout and number of retries for requests. The library enforces a minimum timeout of 5 seconds and at least 1 retry.
from resilient_requester import get_request
# Make a request with custom timeout and retries
response = get_request(
url="https://example.com",
timeout=10,
retries=3
)
if response:
print("Request successful!")
else:
print("Request failed after 3 retries.")
headers
: A dictionary containing default HTTP headers, including a random user-agent.get_request(url, proxy=None, headers=None, timeout=0, retries=0)
Makes an HTTP GET request to the specified URL with retry logic.
url
(str): The URL to request.proxy
(dict, optional): A dictionary specifying proxy settings (e.g., {"http": "http://proxy:8080"}
).headers
(dict, optional): A dictionary of HTTP headers. If not provided, defaults to headers with a random user-agent.timeout
(int, optional): The timeout for the request in seconds. Defaults to 5 if not provided or less than 5.retries
(int, optional): The number of retries for failed requests. Defaults to 1 if not provided or less than 1.requests.Response
: The response object if the request is successful.None
: If the request fails after all retries.response = get_request(
url="https://example.com",
proxy={"http": "http://proxy:8080"},
headers={"User-Agent": "CustomAgent"},
timeout=10,
retries=3
)
helpers.helper_functions
module contains utility functions used by the Requester
class.
get_headers()
Generates default HTTP headers with a random user-agent.
Returns:
dict
: A dictionary of HTTP headers with the following keys:
accept
: "*/*"
accept-language
: "en-GB,en-US;q=0.9,en;q=0.8"
connection
: "keep-alive"
user-agent
: A random user-agent string generated by fake_useragent
.check_params(proxy, headers, timeout, retries)
: Validates and normalizes input parameters.
FAQs
A simple HTTP requester with retry and proxy support
We found that resilient-requester demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.