sassoftware / python-sasctl

Python package and CLI for user-friendly integration with SAS Viya
https://sassoftware.github.io/python-sasctl
Apache License 2.0
45 stars 41 forks source link

urllib3 update to version 2.0.2 causes errors #165

Closed xavierBizoux closed 1 year ago

xavierBizoux commented 1 year ago

Describe the issue After upgrading urllib3 to version 2.0.2, sasctl fails to start a session.

To Reproduce import getpass

from sasctl import Session from sasctl.services import folders

server_name = "server.sas.com" user = "sasdemo" password = getpass.getpass()

with Session(server_name, user, password): folders.list_folders()

Expected behavior Display a list of folders

Stack Trace Traceback (most recent call last): File "/Users/sbxxab/gitRepos/python-sasctl/examples/test_urllib3.py", line 12, in with Session(server_name, user, password): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/sbxxab/gitRepos/python-sasctl/src/sasctl/core.py", line 425, in init self.auth = self._get_authorization_token( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/sbxxab/gitRepos/python-sasctl/src/sasctl/core.py", line 948, in _get_authorization_token return self._request_token_with_oauth( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/sbxxab/gitRepos/python-sasctl/src/sasctl/core.py", line 1346, in _request_token_with_oauth response = super(Session, self).post( ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/sbxxab/gitRepos/python-sasctl/.venv/lib/python3.11/site-packages/requests/sessions.py", line 635, in post return self.request("POST", url, data=data, json=json, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/sbxxab/gitRepos/python-sasctl/src/sasctl/core.py", line 633, in request r = super(Session, self).request( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/sbxxab/gitRepos/python-sasctl/.venv/lib/python3.11/site-packages/requests/sessions.py", line 587, in request resp = self.send(prep, send_kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/sbxxab/gitRepos/python-sasctl/src/sasctl/core.py", line 588, in send response = super(Session, self).send(request, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/sbxxab/gitRepos/python-sasctl/.venv/lib/python3.11/site-packages/requests/sessions.py", line 701, in send r = adapter.send(request, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/sbxxab/gitRepos/python-sasctl/.venv/lib/python3.11/site-packages/requests/adapters.py", line 486, in send resp = conn.urlopen( ^^^^^^^^^^^^^ File "/Users/sbxxab/gitRepos/python-sasctl/.venv/lib/python3.11/site-packages/urllib3/connectionpool.py", line 790, in urlopen response = self._make_request( ^^^^^^^^^^^^^^^^^^^ File "/Users/sbxxab/gitRepos/python-sasctl/.venv/lib/python3.11/site-packages/urllib3/connectionpool.py", line 467, in _make_request self._validate_conn(conn) File "/Users/sbxxab/gitRepos/python-sasctl/.venv/lib/python3.11/site-packages/urllib3/connectionpool.py", line 1092, in _validate_conn conn.connect() File "/Users/sbxxab/gitRepos/python-sasctl/.venv/lib/python3.11/site-packages/urllib3/connection.py", line 635, in connect sock_and_verified = _ssl_wrap_socket_and_match_hostname( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/sbxxab/gitRepos/python-sasctl/.venv/lib/python3.11/site-packages/urllib3/connection.py", line 809, in _ssl_wrap_socket_and_match_hostname _match_hostname( File "/Users/sbxxab/gitRepos/python-sasctl/.venv/lib/python3.11/site-packages/urllib3/connection.py", line 833, in _match_hostname stripped_hostname = asserted_hostname.strip("[]") ^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'bool' object has no attribute 'strip'

Version sasctl 1.9.1

smlindauer commented 1 year ago

This is actually an issue with the requests package itself (see here) not yet supporting urllib3 v2.0.0+. I believe the requests package is waiting to see how urllib3 handles the failed backwards compatibility before attempting to push a major release update.

For the time being, I would downgrade the urllib3 package to <2.0.0 (pip install -U urllib3<2) or reinstall the requests package such that it can dictate their acceptable dependencies.

smlindauer commented 1 year ago

Looks like those errors also propagated to the automated tests. I just pushed bef71103d6beea60f39a77e782215febfddb2789 to adjust the tox.ini set up.

For the time being, I think it's fair to say that we should only be using urllib3<2.0.0 for anything utilizing requests (i.e. most of sasctl).