1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-27 13:34:28 +00:00

Remove Telegram API requests timeout

This commit is contained in:
Steffo 2017-03-12 19:12:14 +01:00
parent b12dcf3ff5
commit 2ffab612f5

View file

@ -131,22 +131,17 @@ class Bot:
async def api_request(self, endpoint, **params): async def api_request(self, endpoint, **params):
"""Send a request to the Telegram API at the specified endpoint.""" """Send a request to the Telegram API at the specified endpoint."""
if "timeout" in params: # TODO: Reintroduce the timeout to prevent stuck requests
t = params["timeout"] + 5 # Create a new session for each request.
else: async with aiohttp.ClientSession() as session:
# Default timeout is 5 seconds. # Send the request to the Telegram API
t = 5 token = self.token
with async_timeout.timeout(t): async with session.request("GET", f"https://api.telegram.org/bot{token}/{endpoint}", params=params) as response:
# Create a new session for each request. # Check for errors in the request
async with aiohttp.ClientSession() as session: if response.status != 200:
# Send the request to the Telegram API raise TelegramAPIError(f"Request returned {response.status} {response.reason}")
token = self.token # Parse the json data as soon it's ready
async with session.request("GET", f"https://api.telegram.org/bot{token}/{endpoint}", params=params) as response: data = await response.json()
# Check for errors in the request
if response.status != 200:
raise TelegramAPIError(f"Request returned {response.status} {response.reason}")
# Parse the json data as soon it's ready
data = await response.json()
# Check for errors in the response # Check for errors in the response
if not data["ok"]: if not data["ok"]:
error = data["description"] error = data["description"]