From a1429f36b2ff90d53c597395bf3029a608fbc17c Mon Sep 17 00:00:00 2001 From: Abhijeet Kaur Date: Mon, 24 Jul 2017 20:01:00 +0530 Subject: [PATCH] bots: Enable googlesearch bot to run by 'zulip-run-bot' command. Since we want our bots to be both python 2 and python 3 compatible, we use six to make up for both of them and run the bot smoothly. 'http.client' was basically used for error-handling by the author of the bot, urllib errors can be handled by the urllib itself. So, using this for simplicity. urllib.request.urlopen raises URLError on protocol errors. --- zulip_bots/zulip_bots/bots/googlesearch/googlesearch.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/zulip_bots/zulip_bots/bots/googlesearch/googlesearch.py b/zulip_bots/zulip_bots/bots/googlesearch/googlesearch.py index edfdb21..0f43172 100644 --- a/zulip_bots/zulip_bots/bots/googlesearch/googlesearch.py +++ b/zulip_bots/zulip_bots/bots/googlesearch/googlesearch.py @@ -1,7 +1,7 @@ # See readme.md for instructions on running this code. from __future__ import print_function import logging -import http.client +from six.moves.urllib import error from six.moves.urllib.request import urlopen # Uses the Google search engine bindings @@ -26,7 +26,7 @@ def get_google_result(search_keywords): try: urls = search(search_keywords, stop=20) urlopen('http://216.58.192.142', timeout=1) - except http.client.RemoteDisconnected as er: + except error.URLError as er: logging.exception(er) return 'Error: No internet connection. {}.'.format(er) except Exception as e: @@ -85,7 +85,7 @@ def test(): urlopen('http://216.58.192.142', timeout=1) print('Success') return True - except http.client.RemoteDisconnected as e: + except error.URLError as e: print('Error: {}'.format(e)) return False