diff options
author | Matt Martz <matt@sivel.net> | 2022-08-31 17:45:56 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-31 15:45:56 -0700 |
commit | c51c5f97a45bb6b9599cdf19baa08d284e76b8d8 (patch) | |
tree | 9fc22ac20661b502d521076fb7e579cdfc092946 | |
parent | 9917b9f9f9af209cee91d3d73bb6ba868b06e247 (diff) | |
download | ansible-c51c5f97a45bb6b9599cdf19baa08d284e76b8d8.tar.gz |
[stable-2.13] Guard urllib3 imports against all exceptions. Fixes #78648 (#78667) (#78672)
(cherry picked from commit f8e24e4)
Co-authored-by: Matt Martz <matt@sivel.net>
-rw-r--r-- | changelogs/fragments/78648-urllib3-import-exceptions.yml | 5 | ||||
-rw-r--r-- | lib/ansible/module_utils/urls.py | 8 |
2 files changed, 9 insertions, 4 deletions
diff --git a/changelogs/fragments/78648-urllib3-import-exceptions.yml b/changelogs/fragments/78648-urllib3-import-exceptions.yml new file mode 100644 index 0000000000..35cb58dbe2 --- /dev/null +++ b/changelogs/fragments/78648-urllib3-import-exceptions.yml @@ -0,0 +1,5 @@ +bugfixes: +- urls - Guard imports of ``urllib3`` by catching ``Exception`` instead of + ``ImportError`` to prevent exceptions in the import process of optional + dependencies from preventing use of ``urls.py`` + (https://github.com/ansible/ansible/issues/78648) diff --git a/lib/ansible/module_utils/urls.py b/lib/ansible/module_utils/urls.py index 7e7ba225a3..52c60dd9a0 100644 --- a/lib/ansible/module_utils/urls.py +++ b/lib/ansible/module_utils/urls.py @@ -114,19 +114,19 @@ try: HAS_URLLIB3_SSL_WRAP_SOCKET = False try: from urllib3.contrib.pyopenssl import PyOpenSSLContext - except ImportError: + except Exception: from requests.packages.urllib3.contrib.pyopenssl import PyOpenSSLContext HAS_URLLIB3_PYOPENSSLCONTEXT = True -except ImportError: +except Exception: # urllib3<1.15,>=1.6 HAS_URLLIB3_PYOPENSSLCONTEXT = False try: try: from urllib3.contrib.pyopenssl import ssl_wrap_socket - except ImportError: + except Exception: from requests.packages.urllib3.contrib.pyopenssl import ssl_wrap_socket HAS_URLLIB3_SSL_WRAP_SOCKET = True - except ImportError: + except Exception: pass # Select a protocol that includes all secure tls protocols |