2

我想知道是否有办法关闭与exchangelib的连接。

这是我的设置和连接功能;我需要定义一个close_conection()函数,但没有找到任何阅读文档的内容。

class Exchange:
    def __init__(self, username, password, server):
        """"""
        self.username = username
        self.password = password
        self.server = server  
    def account(self):
        """Setup and connecting"""
        creds = Credentials(
            username=self.username,
            password=self.password
        )
        config = Configuration(server=self.server, credentials=creds)
        account = Account(
            primary_smtp_address=self.username,
            autodiscover=False, 
            config=config,
            access_type=DELEGATE
        )
        return account
4

1 回答 1

1

exchangelib 将在垃圾收集时关闭 TCP 连接。见https://github.com/ecederstrand/exchangelib/blob/3c10bc7ad0e0ba2aa0b4a55eb95d234ff8c6091a/exchangelib/protocol.py#L114

您还可以通过以下方式显式关闭连接:account.protocol.close()

于 2019-11-07T08:28:09.360 回答