From 670840021ddea4908a2e68144ce6c009d7e16e96 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Mon, 28 Oct 2024 00:44:15 +0000 Subject: [PATCH] use requests.Session --- tqdm/contrib/discord.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tqdm/contrib/discord.py b/tqdm/contrib/discord.py index bafd8b61..59d63e18 100644 --- a/tqdm/contrib/discord.py +++ b/tqdm/contrib/discord.py @@ -11,7 +11,7 @@ Usage: from os import getenv from warnings import warn -import requests +from requests import Session from ..auto import tqdm as tqdm_auto from ..std import TqdmWarning @@ -32,6 +32,7 @@ class DiscordIO(MonoWorker): super().__init__() self.token = token self.channel_id = channel_id + self.session = Session() self.text = self.__class__.__name__ self.message_id @@ -40,7 +41,7 @@ class DiscordIO(MonoWorker): if hasattr(self, '_message_id'): return self._message_id try: - res = requests.post( + res = self.session.post( f'{self.API}/channels/{self.channel_id}/messages', headers={'Authorization': f'Bot {self.token}', 'User-Agent': self.UA}, json={'content': f"`{self.text}`"}).json() @@ -66,7 +67,7 @@ class DiscordIO(MonoWorker): self.text = s try: future = self.submit( - requests.patch, + self.session.patch, f'{self.API}/channels/{self.channel_id}/messages/{message_id}', headers={'Authorization': f'Bot {self.token}', 'User-Agent': self.UA}, json={'content': f"`{self.text}`"}) @@ -79,7 +80,7 @@ class DiscordIO(MonoWorker): """Deletes internal `message_id`.""" try: future = self.submit( - requests.delete, + self.session.delete, f'{self.API}/channels/{self.channel_id}/messages/{self.message_id}', headers={'Authorization': f'Bot {self.token}', 'User-Agent': self.UA}) except Exception as e: