我想知道是否有办法关闭与 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
最佳答案
exchangelib 将在垃圾回收时关闭 TCP 连接。请参阅https://github.com/ecederstrand/exchangelib/blob/3c10bc7ad0e0ba2aa0b4a55eb95d234ff8c6091a/exchangelib/protocol.py#L114
您还可以使用以下方式显式关闭连接:account.protocol.close()
关于python - Exchangelib 关闭连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58732311/