diff --git a/openhands/storage/s3.py b/openhands/storage/s3.py index 429e660011e4..cb723355155d 100644 --- a/openhands/storage/s3.py +++ b/openhands/storage/s3.py @@ -45,7 +45,8 @@ def write(self, path: str, contents: str | bytes) -> None: def read(self, path: str) -> str: try: response = self.client.get_object(Bucket=self.bucket, Key=path) - return response['Body'].read().decode('utf-8') + with response['Body'] as stream: + return stream.read().decode('utf-8') except botocore.exceptions.ClientError as e: # Catch all S3-related errors if e.response['Error']['Code'] == 'NoSuchBucket':