From d25ec2025b66b097d55ea1c7e23cf6ed4945258e Mon Sep 17 00:00:00 2001 From: Florian Strzelecki Date: Fri, 7 Jan 2022 00:09:28 +0100 Subject: [PATCH 1/2] isup: catch up errors from get site and from requests differently --- sopel/modules/isup.py | 9 +++++++-- test/modules/test_modules_isup.py | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/sopel/modules/isup.py b/sopel/modules/isup.py index 0b98858366..9f66486460 100644 --- a/sopel/modules/isup.py +++ b/sopel/modules/isup.py @@ -59,10 +59,13 @@ def handle_isup(bot, trigger, secure=True): """ try: site = get_site_url(trigger.group(2)) - response = requests.head(site, verify=secure, timeout=(10.0, 5.0)) - response.raise_for_status() except ValueError as error: bot.reply(str(error)) + return + + try: + response = requests.head(site, verify=secure, timeout=(10.0, 5.0)) + response.raise_for_status() except requests.exceptions.SSLError: bot.say( '{} looks down to me (SSL error). Try using `{}isupinsecure`.' @@ -83,6 +86,8 @@ def handle_isup(bot, trigger, secure=True): bot.say( '{} looks down to me (connection error).' .format(site)) + except ValueError: + bot.reply('"{}" is not a valid URL.'.format(site)) else: # If no exception happened, the request must have succeeded. bot.say(site + ' looks fine to me.') diff --git a/test/modules/test_modules_isup.py b/test/modules/test_modules_isup.py index 4debb8608c..92bc94ecb6 100644 --- a/test/modules/test_modules_isup.py +++ b/test/modules/test_modules_isup.py @@ -114,7 +114,7 @@ def test_isup_command_unparseable(irc, bot, user, requests_mock): """Test URL that can't be parsed.""" requests_mock.head( 'http://.foo', - exc=ValueError("Failed to parse: '.foo', label empty or too long"), + exc=ValueError("Invalid URL"), ) irc.pm(user, '.isup .foo') @@ -122,7 +122,7 @@ def test_isup_command_unparseable(irc, bot, user, requests_mock): assert len(bot.backend.message_sent) == 1, ( '.isup command should output exactly one line') assert bot.backend.message_sent == rawlist( - 'PRIVMSG User :User: Failed to parse: \'.foo\', label empty or too long' + 'PRIVMSG User :User: "http://.foo" is not a valid URL.' ) From 96d37e5c4ffddaa1329c704d70a4892cb942a61d Mon Sep 17 00:00:00 2001 From: Florian Strzelecki Date: Fri, 7 Jan 2022 00:16:35 +0100 Subject: [PATCH 2/2] requirements: narrow requests to >=2.24 Sopel's other dependencies require requests>=24 at minimum, so there is no sense in requiring only 2.0. Also, 2.0 is old, 2.24 is a good minimum (and it's still compatible with 2.7). --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index c8fb3ea86a..9937ec9c3b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,6 +2,6 @@ xmltodict==0.12 pytz praw>=4.0.0,<6.0.0 geoip2>=4.0,<5.0 -requests>=2.0.0,<3.0.0 +requests>=2.24.0,<3.0.0 dnspython<3.0 sqlalchemy>=1.4,<1.5