Skip to content

Commit ae98e90

Browse files
Merge pull request #42 from trendelkampschroer/bugfix/support_method_whitelist_for_old_urllib3_versions
Bugfix/support method whitelist for old urllib3 versions
2 parents deee759 + 55213a0 commit ae98e90

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

CHANGELOG.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,17 @@ Possible types of changes are:
2020
Unreleased
2121
----------
2222

23+
Fixed
24+
'''''
25+
- Ensure compatibility with ``urllib3`` versions smaller than ``1.26.0`` - the first version that introduced the ``allowed_methods`` argument
26+
and started deprecation of the ``method_whitelist`` argument.
27+
2328
1.4.2 - 24.02.2021
2429
------------------
2530

2631
Fixed
2732
'''''
28-
- Changed keyword argument of underlying dependency urllib3 from `method_whitelist` to `allowed_methods` to avoid deprecation warning (#39)
33+
- Changed keyword argument of underlying dependency urllib3 from ``method_whitelist`` to ``allowed_methods`` to avoid deprecation warning (#39)
2934

3035
1.4.1 - 06.07.2020
3136
------------------

fs_gcsfs/_gcsfs.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from typing import Optional, List, Union, Tuple, Iterator, MutableMapping, Any
1010

1111
import google
12+
import urllib3
1213
from fs import ResourceType, errors, tools
1314
from fs.base import FS
1415
from fs.info import Info
@@ -19,6 +20,7 @@
1920
from fs.time import datetime_to_epoch
2021
from google.cloud.storage import Client
2122
from google.cloud.storage.blob import Blob
23+
from packaging import version
2224
from requests.adapters import HTTPAdapter
2325
from urllib3.util.retry import Retry
2426

@@ -76,10 +78,16 @@ def __init__(self,
7678
self.client = Client()
7779

7880
if retry:
79-
adapter = HTTPAdapter(max_retries=Retry(total=retry,
80-
status_forcelist=[429, 502, 503, 504],
81-
allowed_methods=False, # retry on any HTTP method
82-
backoff_factor=0.5))
81+
# urllib3: "method_whitelist" was deprecated in favour of "allowed_methods" in version 1.26.0
82+
# Ensure compatibility with versions < 1.26.0 while at the same time avoiding the `DeprecationWarning`
83+
# for versions >= 1.26.0
84+
key = "allowed_methods" if version.parse(urllib3.__version__) >= version.parse("1.26.0") else "method_whitelist"
85+
kwargs = {key: False} # retry on any HTTP method
86+
max_retries = Retry(total=retry,
87+
status_forcelist=[429, 502, 503, 504],
88+
backoff_factor=0.5,
89+
**kwargs)
90+
adapter = HTTPAdapter(max_retries=max_retries)
8391
self.client._http.mount("https://", adapter)
8492

8593
self.bucket = self.client.bucket(self._bucket_name)

0 commit comments

Comments
 (0)