python 3.x - NotImplementedError when testing S3 connection during __init__ in s3fs.S3FileSystem subclass - Stack Overflow

I'm creating a subclass of s3fs.S3FileSystem that connects to either AWS S3 or MinIO based on envi

I'm creating a subclass of s3fs.S3FileSystem that connects to either AWS S3 or MinIO based on environment variables. The connection should fail immediately during initialization if credentials are invalid.

The parent class accepts invalid credentials during initialization, only failing later during actual operations (like ls() or file access).

When I try to validate the connection by calling self.ls('') inside __init__ (via a _test_connection() helper), I get a NotImplementedError. However, if I call the same method after instantiation, it works correctly.

class S3MinioConnector(s3fs.S3FileSystem):
    def __init__(self) -> None:
        # ... (setup code)
        super().__init__(**params)  # Initialize parent
        self._test_connection()    # Fails here with NotImplementedError

    def _test_connection(self):
        self.ls('')  # Inherited method

How can I properly validate the connection during initialization without:

  • Getting NotImplementedError?

  • Using obscure solutions like time.sleep(2)?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744192046a4562477.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信