Skip to content

Commit

Permalink
Merge pull request #42 from trendelkampschroer/bugfix/support_method_…
Browse files Browse the repository at this point in the history
…whitelist_for_old_urllib3_versions

Bugfix/support method whitelist for old urllib3 versions
  • Loading branch information
trendelkampschroer authored Mar 24, 2021
2 parents deee759 + 55213a0 commit ae98e90
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@ Possible types of changes are:
Unreleased
----------

Fixed
'''''
- Ensure compatibility with ``urllib3`` versions smaller than ``1.26.0`` - the first version that introduced the ``allowed_methods`` argument
and started deprecation of the ``method_whitelist`` argument.

1.4.2 - 24.02.2021
------------------

Fixed
'''''
- Changed keyword argument of underlying dependency urllib3 from `method_whitelist` to `allowed_methods` to avoid deprecation warning (#39)
- Changed keyword argument of underlying dependency urllib3 from ``method_whitelist`` to ``allowed_methods`` to avoid deprecation warning (#39)

1.4.1 - 06.07.2020
------------------
Expand Down
16 changes: 12 additions & 4 deletions fs_gcsfs/_gcsfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from typing import Optional, List, Union, Tuple, Iterator, MutableMapping, Any

import google
import urllib3
from fs import ResourceType, errors, tools
from fs.base import FS
from fs.info import Info
Expand All @@ -19,6 +20,7 @@
from fs.time import datetime_to_epoch
from google.cloud.storage import Client
from google.cloud.storage.blob import Blob
from packaging import version
from requests.adapters import HTTPAdapter
from urllib3.util.retry import Retry

Expand Down Expand Up @@ -76,10 +78,16 @@ def __init__(self,
self.client = Client()

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

self.bucket = self.client.bucket(self._bucket_name)
Expand Down

0 comments on commit ae98e90

Please sign in to comment.