Skip to content

Commit a2fddbe

Browse files
lisitskyjh0ker
authored andcommitted
Fix telegram API change, returning '404 Not found' (python-telegram-bot#461)
* Fix telegram API change, returning '404 Not found' with raising own TelegramError rather native exception * Change exception to InvalidToken in test and request util * Added myself to AUTHORS. Thx for appreciation :)
1 parent 68e87db commit a2fddbe

3 files changed

Lines changed: 6 additions & 3 deletions

File tree

AUTHORS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ The following wonderful people contributed directly or indirectly to this projec
1313
- `bimmlerd <https://github.com/bimmlerd>`_
1414
- `Eli Gao <https://github.com/eligao>`_
1515
- `ErgoZ Riftbit Vaper <https://github.com/ergoz>`_
16+
- `Eugene Lisitsky <https://github.com/lisitsky>`_
1617
- `franciscod <https://github.com/franciscod>`_
1718
- `Jacob Bom <https://github.com/bomjacob>`_
1819
- `JASON0916 <https://github.com/JASON0916>`_

telegram/utils/request.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
from urllib3.connection import HTTPConnection
3232

3333
from telegram import (InputFile, TelegramError)
34-
from telegram.error import Unauthorized, NetworkError, TimedOut, BadRequest, ChatMigrated, \
35-
RetryAfter
34+
from telegram.error import Unauthorized, InvalidToken, NetworkError, TimedOut, BadRequest, \
35+
ChatMigrated, RetryAfter
3636

3737
logging.getLogger('urllib3').setLevel(logging.WARNING)
3838

@@ -150,6 +150,8 @@ def _request_wrapper(self, *args, **kwargs):
150150
raise Unauthorized()
151151
elif resp.status == 400:
152152
raise BadRequest(repr(message))
153+
elif resp.status == 404:
154+
raise InvalidToken()
153155
elif resp.status == 502:
154156
raise NetworkError('Bad Gateway')
155157
else:

tests/test_bot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def testUnauthToken(self):
227227
bot.getMe()
228228

229229
def testInvalidSrvResp(self):
230-
with self.assertRaisesRegexp(telegram.TelegramError, 'Invalid server response'):
230+
with self.assertRaisesRegexp(telegram.error.InvalidToken, 'Invalid token'):
231231
# bypass the valid token check
232232
newbot_cls = type(
233233
'NoTokenValidateBot', (telegram.Bot,), dict(_validate_token=lambda x, y: None))

0 commit comments

Comments
 (0)