Skip to content

Commit a4a6c7e

Browse files
committed
Backport pull request #2235
isup: catch up errors from get site and from requests differently Requirements changes have been adapted to 7.1.x's stack.
1 parent e5a3d3f commit a4a6c7e

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ geoip2>=4.0,<5.0; python_version >= '3.6'
1010
# transitive dependency of geoip2; v2 dropped py2.7 & py3 < 3.6
1111
maxminddb<2.0; python_version < '3.6'
1212
ipaddress<2.0; python_version < '3.3'
13-
requests>=2.0.0,<3.0.0; python_version != '3.3'
13+
requests>=2.24.0,<3.0.0; python_version != '3.3'
1414
# py3.3 doesn't work with the chardet/charset-normalizer detection added in 2.26
15-
requests>=2.0.0,<2.26; python_version == '3.3'
15+
requests>=2.24.0,<2.26; python_version == '3.3'
1616
# transitive dependency of requests
1717
# 2.0 will drop EOL Python 2.7 & 3.5, just like Sopel 8 plans to
1818
urllib3<1.27; python_version != '3.3' and python_version != '3.4'

sopel/modules/isup.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,13 @@ def handle_isup(bot, trigger, secure=True):
6060
"""
6161
try:
6262
site = get_site_url(trigger.group(2))
63-
response = requests.head(site, verify=secure, timeout=(10.0, 5.0))
64-
response.raise_for_status()
6563
except ValueError as error:
6664
bot.reply(str(error))
65+
return
66+
67+
try:
68+
response = requests.head(site, verify=secure, timeout=(10.0, 5.0))
69+
response.raise_for_status()
6770
except requests.exceptions.SSLError:
6871
bot.say(
6972
'{} looks down to me (SSL error). Try using `{}isupinsecure`.'
@@ -84,6 +87,8 @@ def handle_isup(bot, trigger, secure=True):
8487
bot.say(
8588
'{} looks down to me (connection error).'
8689
.format(site))
90+
except ValueError:
91+
bot.reply('"{}" is not a valid URL.'.format(site))
8792
else:
8893
# If no exception happened, the request must have succeeded.
8994
bot.say(site + ' looks fine to me.')

test/modules/test_modules_isup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,15 @@ def test_isup_command_unparseable(irc, bot, user, requests_mock):
115115
"""Test URL that can't be parsed."""
116116
requests_mock.head(
117117
'http://.foo',
118-
exc=ValueError("Failed to parse: '.foo', label empty or too long"),
118+
exc=ValueError("Invalid URL"),
119119
)
120120

121121
irc.pm(user, '.isup .foo')
122122

123123
assert len(bot.backend.message_sent) == 1, (
124124
'.isup command should output exactly one line')
125125
assert bot.backend.message_sent == rawlist(
126-
'PRIVMSG User :User: Failed to parse: \'.foo\', label empty or too long'
126+
'PRIVMSG User :User: "http://.foo" is not a valid URL.'
127127
)
128128

129129

0 commit comments

Comments
 (0)