'AttributeError: 'Retry' object has no attribute 'method_whitelist'

The following error occurred while trying to run code:

Traceback (most recent call last):

    response = session.post(base_url, params={'query': filename_query})
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 578, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 530, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 643, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 805, in urlopen
    if retries.is_retry(method, response.status, has_retry_after):
  File "/usr/local/lib/python3.7/site-packages/urllib3/util/retry.py", line 343, in is_retry
    if not self._is_method_retryable(method):
  File "/usr/local/lib/python3.7/site-packages/urllib3/util/retry.py", line 331, in _is_method_retryable
    if self.method_whitelist and method.upper() not in self.method_whitelist:
AttributeError: 'Retry' object has no attribute 'method_whitelist'

Could someone help me with this?



Solution 1:[1]

I don't know your specific case since there is not much info. Nevertheless, I had the same error while using the requests package in an Apache Beam pipeline

The thing is that method_whitelist was deprecated and removed from urllib3==1.26.0 onwards, as stated in the release changelog

The solution in my case was to set the urllib version to a previous one, adding urllib3==1.25.11 to my requirements.txt

Solution 2:[2]

There was a similar problem for me. In my case, the problem was that the pyfcm library was not updated. This library is for sending push notifications. My problem was solved by updating this library.

pip install pyfcm --upgrade

Solution 3:[3]

I solved a similar problem by installing requests==1.26.0 and urllib3==1.26.2.

Solution 4:[4]

Use allowed_methods instead of method_whitelist. The latter was removed at some point and was replaced by the former.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 GRT
Solution 2 H.sojoodi
Solution 3 Cody Gray
Solution 4 luk2302