我需要有关 boto3 超出最大递归深度的递归错误的帮助。当我在推理脚本中初始化 s3 客户端以允许我读取 s3 对象时,就会发生这种情况。我们将非常感谢您的见解! 2 个月前发布的类似问题在这里:AWS SageMaker Endpoint: Maximum Recursion Depth Exceeded Error When Calling boto3.client("s3") 这是导致错误的相关代码块:
def get_video_bytes_from_s3(bucket_name, key):
s3_client = boto3.client('s3')
try:
video_object = s3_client.get_object(Bucket= bucket_name, Key=key)
video_bytes = video_object['Body'].read()
return video_bytes
except Exception as e:
print(f"Failed to fetch video from S3: {e}")
来自 CloudWatch 的错误日志:
Traceback (most recent call last):
File "/sagemaker/python_service.py", line 423, in _handle_invocation_post
res.body, res.content_type = handlers(data, context)
File "/opt/ml/model/code/inference.py", line 156, in handler
video_bytes = get_video_bytes_from_s3(key)
File "/opt/ml/model/code/inference.py", line 16, in get_video_bytes_from_s3
s3_client = boto3.client('s3')
File "/usr/local/lib/python3.10/site-packages/boto3/__init__.py", line 92, in client
return _get_default_session().client(*args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/boto3/session.py", line 299, in client
return self._session.create_client(
File "/usr/local/lib/python3.10/site-packages/botocore/session.py", line 997, in create_client
client = client_creator.create_client(
File "/usr/local/lib/python3.10/site-packages/botocore/client.py", line 159, in create_client
client_args = self._get_client_args(
File "/usr/local/lib/python3.10/site-packages/botocore/client.py", line 490, in _get_client_args
return args_creator.get_client_args(
File "/usr/local/lib/python3.10/site-packages/botocore/args.py", line 137, in get_client_args
endpoint = endpoint_creator.create_endpoint(
File "/usr/local/lib/python3.10/site-packages/botocore/endpoint.py", line 409, in create_endpoint
http_session = http_session_cls(
File "/usr/local/lib/python3.10/site-packages/botocore/httpsession.py", line 323, in __init__
self._manager = PoolManager(**self._get_pool_manager_kwargs())
File "/usr/local/lib/python3.10/site-packages/botocore/httpsession.py", line 341, in _get_pool_manager_kwargs
'ssl_context': self._get_ssl_context(),
File "/usr/local/lib/python3.10/site-packages/botocore/httpsession.py", line 350, in _get_ssl_context
return create_urllib3_context()
File "/usr/local/lib/python3.10/site-packages/botocore/httpsession.py", line 139, in create_urllib3_context
context.options |= options
File "/usr/local/lib/python3.10/ssl.py", line 620, in options
super(SSLContext, SSLContext).options.__set__(self, value)
File "/usr/local/lib/python3.10/ssl.py", line 620, in options
super(SSLContext, SSLContext).options.__set__(self, value)
File "/usr/local/lib/python3.10/ssl.py", line 620, in options
super(SSLContext, SSLContext).options.__set__(self, value)
[Previous line repeated 479 more times]
我尝试过使用
gevent
进行猴子修补,即通过放置这个
monkey.patch_all()
在我导入的顶部,但它没有解决问题。感谢您的见解。
谢谢。
我能够通过在模型容器中设置此环境变量来规避该问题
SAGEMAKER_GUNICORN_WORKER_CLASS = "sync"
。受到此问题的启发https://github.com/aws/amazon-sagemaker-examples/issues/1561。