From 0545c9834fecff94f14ef0ca2ef96496ec83f362 Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Wed, 23 Oct 2024 21:03:20 +0200 Subject: [PATCH] More robust when not configured --- requests_util/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/requests_util/__init__.py b/requests_util/__init__.py index 8dafd8d..ccefc71 100644 --- a/requests_util/__init__.py +++ b/requests_util/__init__.py @@ -79,8 +79,9 @@ def setup_limiter( Will always return the given session itself. """ - if requests_ratelimiter: + if requests_ratelimiter and limiter_args: session.mount(url_prefix, requests_ratelimiter.LimiterAdapter(**limiter_args)) if requests_cache and expire_after: - session.settings.urls_expire_after[url_prefix] = expire_after + if settings := getattr(session, 'settings', None): + settings.urls_expire_after[url_prefix] = expire_after return session