From 16349ac69a9143519fa134fc3e48d24f31c311fe Mon Sep 17 00:00:00 2001 From: Leandro Toledo Date: Wed, 11 Nov 2015 11:31:20 -0200 Subject: [PATCH 1/9] Releasing v2.9.2 --- CHANGES.rst | 6 ++++++ docs/source/conf.py | 2 +- setup.py | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 74031d835..7f8527ba2 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,3 +1,9 @@ +**2015-11-11** + +*Released 2.9.2* + +- Error handling on request timeouts has been improved + **2015-11-10** *Released 2.9.1* diff --git a/docs/source/conf.py b/docs/source/conf.py index 5d717915e..ab68ae745 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -60,7 +60,7 @@ author = u'Leandro Toledo' # The short X.Y version. version = '2.9' # The full version, including alpha/beta/rc tags. -release = '2.9.1' +release = '2.9.2' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/setup.py b/setup.py index a12c9936d..317d47da9 100644 --- a/setup.py +++ b/setup.py @@ -26,7 +26,7 @@ def requirements(): setup( name='python-telegram-bot', - version='2.9.1', + version='2.9.2', author='Leandro Toledo', author_email='leandrotoledodesouza@gmail.com', license='LGPLv3', From 7993328ff7a021ad3ded8352574aec40aed53b94 Mon Sep 17 00:00:00 2001 From: Leandro Toledo Date: Wed, 11 Nov 2015 12:04:23 -0200 Subject: [PATCH 2/9] Enable travis for PRs --- .travis.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index bd742f71c..e7f038ec4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,7 @@ install: - pip install coveralls - pip install -r requirements.txt script: - nosetests --with-coverage --cover-package telegram/ + - '[ "${TRAVIS_PULL_REQUEST}" = "false" ] && bundle exec rake tests:integration || false' + - nosetests --with-coverage --cover-package telegram/ after_success: - coveralls + - coveralls From 968b19e8b730d11f28a249d55ff76ee8dbef20a8 Mon Sep 17 00:00:00 2001 From: Leandro Toledo Date: Wed, 11 Nov 2015 12:07:43 -0200 Subject: [PATCH 3/9] Rolling back travis settings --- .travis.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index e7f038ec4..bd742f71c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,6 @@ install: - pip install coveralls - pip install -r requirements.txt script: - - '[ "${TRAVIS_PULL_REQUEST}" = "false" ] && bundle exec rake tests:integration || false' - - nosetests --with-coverage --cover-package telegram/ + nosetests --with-coverage --cover-package telegram/ after_success: - - coveralls + coveralls From 596fc2aeda7edc109648dac4ba14ae9095289c69 Mon Sep 17 00:00:00 2001 From: Leandro Toledo Date: Wed, 11 Nov 2015 12:27:07 -0200 Subject: [PATCH 4/9] Adding OSX and lint/pep8 tests to Travis --- .travis.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index bd742f71c..51c0519a4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,7 @@ language: python +os: + - linux + - osx python: - "2.6" - "2.7" @@ -7,9 +10,11 @@ python: - "pypy" - "pypy3" install: - - pip install coveralls + - pip install pylint flake8 coveralls - pip install -r requirements.txt script: nosetests --with-coverage --cover-package telegram/ + pylint -E telegram + flake8 telegram after_success: coveralls From 8c0bcbf5bb6823310455a01bb48e4d0e51def798 Mon Sep 17 00:00:00 2001 From: Leandro Toledo Date: Wed, 11 Nov 2015 12:28:34 -0200 Subject: [PATCH 5/9] Fixes typo on .travis.yml --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 51c0519a4..1491f5970 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,8 +13,8 @@ install: - pip install pylint flake8 coveralls - pip install -r requirements.txt script: - nosetests --with-coverage --cover-package telegram/ - pylint -E telegram - flake8 telegram + - nosetests --with-coverage --cover-package telegram/ + - pylint -E telegram + - flake8 telegram after_success: coveralls From f08dca0af6d175cb3de4f8996ab6174e4cbf02a7 Mon Sep 17 00:00:00 2001 From: Leandro Toledo Date: Wed, 11 Nov 2015 12:39:09 -0200 Subject: [PATCH 6/9] Fixes pylint for Py2.6 --- .travis.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1491f5970..ef16b1137 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,4 @@ language: python -os: - - linux - - osx python: - "2.6" - "2.7" @@ -14,7 +11,7 @@ install: - pip install -r requirements.txt script: - nosetests --with-coverage --cover-package telegram/ - - pylint -E telegram - flake8 telegram + - 'if [[ $TRAVIS_PYTHON_VERSION == 2.6 ]]; then pylint -E telegram; fi' after_success: coveralls From c64e5770491134b5ffdbfe1decc4895bd8163994 Mon Sep 17 00:00:00 2001 From: Leandro Toledo Date: Wed, 11 Nov 2015 12:41:07 -0200 Subject: [PATCH 7/9] Fixes pylint for Py2.6 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ef16b1137..6009539b9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,6 @@ install: script: - nosetests --with-coverage --cover-package telegram/ - flake8 telegram - - 'if [[ $TRAVIS_PYTHON_VERSION == 2.6 ]]; then pylint -E telegram; fi' + - 'if [[ $TRAVIS_PYTHON_VERSION != 2.6 ]]; then pylint -E telegram; fi' after_success: coveralls From ff0d724f321bb286c6a5ad59ed96463b5c054ee1 Mon Sep 17 00:00:00 2001 From: Rahiel Kasim Date: Thu, 12 Nov 2015 17:26:25 +0100 Subject: [PATCH 8/9] improve echobot with cleaner code and basic exception handling --- examples/echobot.py | 52 +++++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/examples/echobot.py b/examples/echobot.py index c9e9992e3..949b0255a 100644 --- a/examples/echobot.py +++ b/examples/echobot.py @@ -1,6 +1,7 @@ #!/usr/bin/env python +# -*- coding: utf-8 -*- # -# Simple Bot to reply Telegram messages +# Simple Bot to reply to Telegram messages # Copyright (C) 2015 Leandro Toledo de Souza # # This program is free software: you can redistribute it and/or modify @@ -19,13 +20,16 @@ import logging import telegram +from time import sleep - -LAST_UPDATE_ID = None +try: + from urllib.error import URLError +except ImportError: + from urllib2 import URLError # python 2 def main(): - global LAST_UPDATE_ID + update_id = None logging.basicConfig( format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') @@ -33,33 +37,35 @@ def main(): # Telegram Bot Authorization Token bot = telegram.Bot('TOKEN') - # This will be our global variable to keep the latest update_id when requesting - # for updates. It starts with the latest update_id if available. - try: - LAST_UPDATE_ID = bot.getUpdates()[-1].update_id - except IndexError: - LAST_UPDATE_ID = None - while True: - echo(bot) + try: + update_id = echo(bot, update_id) + except telegram.TelegramError as e: + # These are network problems with Telegram. + if e.message in ("Bad Gateway", "Timed out"): + sleep(1) + else: + raise e + except URLError as e: + # These are network problems on our end. + sleep(1) -def echo(bot): - global LAST_UPDATE_ID +def echo(bot, update_id): - # Request updates after the last updated_id - for update in bot.getUpdates(offset=LAST_UPDATE_ID, timeout=10): - # chat_id is required to reply any message + # Request updates after the last update_id + for update in bot.getUpdates(offset=update_id, timeout=10): + # chat_id is required to reply to any message chat_id = update.message.chat_id - reply_text = update.message.text + update_id = update.update_id + 1 + message = update.message.text - if reply_text: - # Reply the message + if message: + # Reply to the message bot.sendMessage(chat_id=chat_id, - text=reply_text) + text=message) - # Updates global offset to get the new updates - LAST_UPDATE_ID = update.update_id + 1 + return update_id if __name__ == '__main__': From 10451509f1ffd096cad16ff56199b599645c7c9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jannes=20H=C3=B6ke?= Date: Thu, 12 Nov 2015 19:15:39 +0100 Subject: [PATCH 9/9] fix for issue #79 --- telegram/utils/request.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/telegram/utils/request.py b/telegram/utils/request.py index 87ccccc4c..430d98482 100644 --- a/telegram/utils/request.py +++ b/telegram/utils/request.py @@ -110,7 +110,11 @@ def post(url, if error.getcode() == 502: raise TelegramError('Bad Gateway') - message = _parse(error.read()) + try: + message = _parse(error.read()) + except ValueError: + message = 'Unknown HTTPError' + raise TelegramError(message) except (SSLError, socket.timeout) as error: if "operation timed out" in str(error):