marcospereirampj / python-keycloak

MIT License
731 stars 304 forks source link

'Retry' object has no attribute 'allowed_methods' #196

Open remyguillaume opened 3 years ago

remyguillaume commented 3 years ago

Hello,

I've just tried to migrate to the last version 0.25.0, but when creating a KeycloakOpenId object:

keycloak_openid = KeycloakOpenID(server_url=service_url,
                                 realm_name=service_realm,
                                 client_id=service_client_id)

I'm now getting the following error :

File "/usr/local/lib/python3.6/dist-packages/keycloak/connection.py", line 57, in __init__
    allowed_methods = set(adapter.max_retries.allowed_methods)
AttributeError: 'Retry' object has no attribute 'allowed_methods'

Everything works perfectly with version 0.24.0. Is there something special to do when migrating to 0.25.0?

Thanks!

David-Lor commented 3 years ago

It seems to be a problem with a deprecated method from urllib3 (used by requests): https://stackoverflow.com/questions/65289720/attributeerror-retry-object-has-no-attribute-method-whitelist

In my environment, installing python-keycloak-0.25.0 also installs requests-2.25.1 and urllib3-1.26.5. This works fine, but I started having this problem after running pip install against a requirements.txt file that I have for test purposes that downgrades the requirements.txt version to 2.24.0.

I guess that a quick fix would be to force freezing the requests and urllib3 packages to the versions that are installed by default (that seem to work fine):

pip install requests==2.25.1 urllib3==1.26.5

I think requirements.txt for python-keycloak may be reviewed to avoid this issue.

saldang commented 2 years ago

I have the same problem with a Google Colab notebook, also with the fixed requirements version.

mamelend commented 2 years ago

I'm having the same issue in a Jupyter notebook.

robin-thoni commented 2 years ago

I encountered the same problem within Saltstack inside Docker. After hours of troubleshooting, I found out the problem was Python using urllib3 from the python-pip-whl Debian package, rather than from pip:

root@salt-minion1:/# ls /usr/share/python-wheels/
CacheControl-0.11.7-py2.py3-none-any.whl  distro-1.3.0-py2.py3-none-any.whl pip-18.1-py2.py3-none-any.whl         retrying-1.3.3-py2.py3-none-any.whl
appdirs-1.4.3-py2.py3-none-any.whl    html5lib-1.0.1-py2.py3-none-any.whl   pkg_resources-0.0.0-py2.py3-none-any.whl  setuptools-40.8.0-py2.py3-none-any.whl
certifi-2018.8.24-py2.py3-none-any.whl    idna-2.6-py2.py3-none-any.whl     progress-1.2-py2.py3-none-any.whl     six-1.12.0-py2.py3-none-any.whl
chardet-3.0.4-py2.py3-none-any.whl    ipaddress-0.0.0-py2.py3-none-any.whl  pyparsing-2.2.0-py2.py3-none-any.whl      urllib3-1.24.1-py2.py3-none-any.whl
colorama-0.3.7-py2.py3-none-any.whl   lockfile-0.12.2-py2.py3-none-any.whl  pytoml-0.1.2-py2.py3-none-any.whl     webencodings-0.5.1-py2.py3-none-any.whl
distlib-0.2.8-py2.py3-none-any.whl    packaging-19.0-py2.py3-none-any.whl   requests-2.21.0-py2.py3-none-any.whl      wheel-0.32.3-py2.py3-none-any.whl

root@salt-minion1:/# dpkg -S /usr/share/python-wheels/urllib3-1.24.1-py2.py3-none-any.whl/
python-pip-whl: /usr/share/python-wheels/urllib3-1.24.1-py2.py3-none-any.whl

That's because I bootstrapped pip with the python3-pip package. Installing pip from pip itself, then removing both python-pip-whl and python3-pip packages solved the problem:

apt-get install python3-pip
pip3 install -U pip
apt-get remove python-pip-whl python3-pip
pip3 install ...

@saldang @mamelend I suggest both of you to check your python path and where urllib3 and request are coming from

ishikagoelnov commented 1 year ago

I have the same problem using Pycharm and fixed upgrading the versions.