sopel-irc / sopel

:robot::speech_balloon: An easy-to-use and highly extensible IRC Bot framework. Formerly Willie.
https://sopel.chat
Other
951 stars 403 forks source link

wikipedia: parse error for template link with fragment #2167

Closed dgw closed 3 years ago

dgw commented 3 years ago

Description

If someone links a template URL with a section fragment, Sopel outputs an unexpected error.

Logs

[2021-07-24 17:12:47,036] sopel.bot            ERROR    - Unexpected error ('parse') from dgw at 2021-07-24
22:12:47.036637. Message was: https://en.wikipedia.org/wiki/Template:Infobox_company#TemplateData
Traceback (most recent call last):
  File "/data/data/com.termux/files/usr/lib/python3.9/site-packages/sopel/bot.py", line 757, in call_rule
    rule.execute(sopel, trigger)
  File "/data/data/com.termux/files/usr/lib/python3.9/site-packages/sopel/plugins/rules.py", line 1057,
  in execute
    exit_code = self._handler(bot, trigger)
  File "/data/data/com.termux/files/usr/lib/python3.9/site-packages/sopel/plugins/rules.py", line 1608,
  in execute_handler
    return handler(bot, trigger, match=trigger)
  File "/data/data/com.termux/files/usr/lib/python3.9/site-packages/sopel/modules/wikipedia.py", line 256,
  in mw_info
    say_section(bot, trigger, match.group(1), unquote(match.group(2)), unquote(match.group(3)))
  File "/data/data/com.termux/files/usr/lib/python3.9/site-packages/sopel/modules/wikipedia.py", line 204,
  in say_section
    snippet = mw_section(server, query, section)
  File "/data/data/com.termux/files/usr/lib/python3.9/site-packages/sopel/modules/wikipedia.py", line 240,
  in mw_section
    parser.feed(data['parse']['text']['*'])
KeyError: 'parse'

Environment

Notes

The same template URL with no fragment yields a perfectly functional, but useless, empty snippet.

<SopelTest> [wikipedia] Template:Infobox company | ""
dgw commented 3 years ago

Bit more digging in API docs and test requests, and I should have a patch for this tonight.