mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-12-22 22:45:09 +01:00
Merge pull request #90 from rahiel/master
raise exception if telegram times out on long-polling
This commit is contained in:
commit
3928e27cf4
1 changed files with 11 additions and 1 deletions
|
@ -20,6 +20,7 @@
|
|||
"""This module contains methods to make POST and GET requests"""
|
||||
|
||||
import json
|
||||
from ssl import SSLError
|
||||
|
||||
try:
|
||||
from urllib.parse import urlencode
|
||||
|
@ -78,6 +79,11 @@ def post(url,
|
|||
Returns:
|
||||
A JSON object.
|
||||
"""
|
||||
if "timeout" in data:
|
||||
timeout = data["timeout"] + 1.
|
||||
else:
|
||||
timeout = None
|
||||
|
||||
try:
|
||||
if InputFile.is_inputfile(data):
|
||||
data = InputFile(data)
|
||||
|
@ -90,7 +96,7 @@ def post(url,
|
|||
data=data.encode(),
|
||||
headers={'Content-Type': 'application/json'})
|
||||
|
||||
result = urlopen(request).read()
|
||||
result = urlopen(request, timeout=timeout).read()
|
||||
except HTTPError as error:
|
||||
if error.getcode() == 403:
|
||||
raise TelegramError('Unauthorized')
|
||||
|
@ -99,7 +105,11 @@ def post(url,
|
|||
|
||||
message = _parse(error.read())
|
||||
raise TelegramError(message)
|
||||
except SSLError as error:
|
||||
if "The read operation timed out" == error.message:
|
||||
raise TelegramError("Timed out")
|
||||
|
||||
raise TelegramError(error.message)
|
||||
return _parse(result)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue