Blob Blame History Raw
From 1bc06edb40e4f46f0ab2bdc90aefc4bca7089051 Mon Sep 17 00:00:00 2001
From: Adam Williamson <awilliam@redhat.com>
Date: Fri, 19 Nov 2021 11:32:12 -0800
Subject: [PATCH] Fix Retry allowed methods for urllib 1.25

This is a follow-up to ae4a3a6. It seems urllib devs went with a
*really* aggressive deprecation schedule here - the kwarg
name they deprecated in 1.26 does not exist in 1.25, which is
still shipped in Fedora 34 (and probably many other stable
distros). If you want the code to work on both 1.25 and 1.26
without any deprecation warnings, you need to fudge it like
this. Inspired by
https://github.com/firebase/firebase-admin-python/pull/532 .

Signed-off-by: Adam Williamson <awilliam@redhat.com>
---
 resultsdb_api.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/resultsdb_api.py b/resultsdb_api.py
index 4b4e5e9..6705b47 100644
--- a/resultsdb_api.py
+++ b/resultsdb_api.py
@@ -129,11 +129,15 @@ class ResultsDBapi(object):
         self.request_auth = request_auth
 
         allowed_methods = list(Retry.DEFAULT_ALLOWED_METHODS) + ["POST"]
+        if hasattr(Retry.DEFAULT, "allowed_methods"):
+            _allow_args = {"allowed_methods": allowed_methods}
+        else:
+            _allow_args = {"method_whitelist": allowed_methods}
         self._retry = Retry(
                 total=max_retries,
                 backoff_factor=backoff_factor,
                 status_forcelist=(500, 502, 503, 504),
-                allowed_methods=allowed_methods
+                **_allow_args
                 )
         self._adapter = HTTPAdapter(max_retries=self._retry)
         self.session = _ResultsDBSession()
-- 
2.33.1