From ab59cfbf931c0bae47f4f9e4b7f6fa4d6d2fc774 Mon Sep 17 00:00:00 2001 From: kenzuyaa Date: Mon, 8 Sep 2025 16:09:08 +0700 Subject: [PATCH] fix(core): add retry and timeout to get_ip_info requests - Import HTTPAdapter from requests.adapters - Configure session adapters for http and https with max_retries=3 - Add timeout of 1 second to the get request in get_ip_info - Ensure retries and timeout improve request reliability and responsiveness --- unshackle/core/utilities.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/unshackle/core/utilities.py b/unshackle/core/utilities.py index 3182326..17b7441 100644 --- a/unshackle/core/utilities.py +++ b/unshackle/core/utilities.py @@ -20,6 +20,7 @@ import requests from construct import ValidationError from langcodes import Language, closest_match from pymp4.parser import Box +from requests.adapters import HTTPAdapter from unidecode import unidecode from unshackle.core.cacher import Cacher @@ -241,7 +242,10 @@ def get_ip_info(session: Optional[requests.Session] = None) -> dict: If you provide a Requests Session with a Proxy, that proxies IP information is what will be returned. """ - return (session or requests.Session()).get("https://ipinfo.io/json").json() + request = session or requests.Session() + request.adapters["http://"] = HTTPAdapter(max_retries=3) + request.adapters["https://"] = HTTPAdapter(max_retries=3) + return request.get("https://ipinfo.io/json", timeout=1).json() def get_cached_ip_info(session: Optional[requests.Session] = None) -> Optional[dict]: