From 514e948c99082120d94996b0db9722b62e6dcdc5 Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Sun, 19 Mar 2023 09:23:56 -0700 Subject: [PATCH] s4cmd: avoid AttributeError on newer botocore Newer botocore has removed `vendored` entirely; try to import carefully. Makes s4cmd work again on botocore-1.29.84. ``` Traceback (most recent call last): File "/usr/lib/python-exec/python3.10/s4cmd", line 33, in sys.exit(load_entry_point('s4cmd==2.1.0', 'console_scripts', 's4cmd')()) File "/usr/lib/python-exec/python3.10/s4cmd", line 25, in importlib_load_entry_point return next(matches).load() File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 171, in load module = import_module(match.group('module')) File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1050, in _gcd_import File "", line 1027, in _find_and_load File "", line 1006, in _find_and_load_unlocked File "", line 688, in _load_unlocked File "", line 883, in exec_module File "", line 241, in _call_with_frames_removed File "/usr/lib64/python-exec/python3.10/s4cmd.py", line 255, in class BotoClient(object): File "/usr/lib64/python-exec/python3.10/s4cmd.py", line 274, in BotoClient botocore.vendored.requests.packages.urllib3.exceptions.ReadTimeoutError, AttributeError: module 'botocore' has no attribute 'vendored' ``` Signed-off-by: Robin H. Johnson --- s4cmd.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/s4cmd.py b/s4cmd.py index bcdf982..5264bd9 100755 --- a/s4cmd.py +++ b/s4cmd.py @@ -271,9 +271,13 @@ class BotoClient(object): S3RetryableErrors = ( socket.timeout, socket.error if IS_PYTHON2 else ConnectionError, - botocore.vendored.requests.packages.urllib3.exceptions.ReadTimeoutError, botocore.exceptions.IncompleteReadError ) + try: + # Newer boto removed botocore.vendored entirely. + S3RetryableErrors += (botocore.vendored.requests.packages.urllib3.exceptions.ReadTimeoutError,) + except AttributeError: + pass # List of API functions we use in s4cmd. ALLOWED_CLIENT_METHODS = [