X Tutup
Skip to content

Bot.getMe() raises inconsistent exceptions #134

@tsnoam

Description

@tsnoam

as agreed in the chat, all exceptions raised should be TelegramError (or similar exceptions)

these are the (inconsistent) exceptions I've seen:

>>> telegram.Bot('not-probably-formatted-token').getMe()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/tsnoam/.local/lib/python2.7/site-packages/telegram/bot.py", line 126, in decorator
    result = func(self, *args, **kwargs)
  File "/home/tsnoam/.local/lib/python2.7/site-packages/telegram/bot.py", line 176, in getMe
    result = request.get(url)
  File "/home/tsnoam/.local/lib/python2.7/site-packages/telegram/utils/request.py", line 67, in get
    return _parse(result)
  File "/home/tsnoam/.local/lib/python2.7/site-packages/telegram/utils/request.py", line 48, in _parse
    data = json.loads(json_data.decode())
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 3621: ordinal not in range(128)

>>> telegram.Bot((9 * '1') + ':' + (35 * 'x')).getMe()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/tsnoam/.local/lib/python2.7/site-packages/telegram/bot.py", line 126, in decorator
    result = func(self, *args, **kwargs)
  File "/home/tsnoam/.local/lib/python2.7/site-packages/telegram/bot.py", line 176, in getMe
    result = request.get(url)
  File "/home/tsnoam/.local/lib/python2.7/site-packages/telegram/utils/request.py", line 65, in get
    result = urlopen(url).read()
  File "/usr/lib64/python2.7/urllib2.py", line 154, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib64/python2.7/urllib2.py", line 437, in open
    response = meth(req, response)
  File "/usr/lib64/python2.7/urllib2.py", line 550, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib64/python2.7/urllib2.py", line 475, in error
    return self._call_chain(*args)
  File "/usr/lib64/python2.7/urllib2.py", line 409, in _call_chain
    result = func(*args)
  File "/usr/lib64/python2.7/urllib2.py", line 558, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 401: Unauthorized

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      X Tutup