We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Wikipedia bot crashes when the query contains multiple word delimit by underscore.
The bot is under `contrib_bots/bots`.  Some error handling is needed.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `contrib_bots/bots/wikipedia/wikipedia.py`
Content:
```
1 from __future__ import absolute_import
2 from __future__ import print_function
3 import requests
4 import logging
5 
6 # See readme.md for instructions on running this code.
7 
8 class WikipediaHandler(object):
9     '''
10     This plugin facilitates searching Wikipedia for a
11     specific key term and returns the top article from the
12     search. It looks for messages starting with '@wikipedia'
13      or '@wiki'.
14 
15     In this example, we write all Wikipedia searches into
16     the same stream that it was called from, but this code
17     could be adapted to write Wikipedia searches to some
18     kind of external issue tracker as well.
19     '''
20 
21     def usage(self):
22         return '''
23             This plugin will allow users to directly search
24             Wikipedia for a specific key term and get the top
25             article that is returned from the search. Users
26             should preface searches with "@wikipedia" or
27             "@wiki".
28             '''
29 
30     def triage_message(self, message, client):
31         original_content = message['content']
32 
33         # This next line of code is defensive, as we
34         # never want to get into an infinite loop of posting Wikipedia
35         # searches for own Wikipedia searches!
36         if message['sender_full_name'] == 'wikipedia-bot':
37             return False
38         is_wikipedia = (original_content.startswith('@wiki') or
39                         original_content.startswith('@wikipedia'))
40 
41         return is_wikipedia
42 
43     def handle_message(self, message, client, state_handler):
44         query = message['content']
45 
46         for prefix in ['@wikipedia', '@wiki']:
47             if query.startswith(prefix):
48                 query = query[len(prefix)+1:]
49                 break
50 
51         query_wiki_link = ('https://en.wikipedia.org/w/api.php?action=query&'
52                            'list=search&srsearch=%s&format=json' % (query,))
53         try:
54             data = requests.get(query_wiki_link)
55         except requests.exceptions.RequestException:
56             logging.error('broken link')
57             return
58 
59         if data.status_code != 200:
60             logging.error('unsuccessful data')
61             return
62 
63         search_string = data.json()['query']['search'][0]['title'].replace(' ', '_')
64         url = 'https://wikipedia.org/wiki/' + search_string
65         new_content = 'For search term "' + query
66         if len(data.json()['query']['search']) == 0:
67             new_content = 'I am sorry. The search term you provided is not found :slightly_frowning_face:'
68         else:
69             new_content = new_content + '", ' + url
70 
71         client.send_message(dict(
72             type=message['type'],
73             to=message['display_recipient'],
74             subject=message['subject'],
75             content=new_content,
76         ))
77 
78 handler_class = WikipediaHandler
79
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/contrib_bots/bots/wikipedia/wikipedia.py b/contrib_bots/bots/wikipedia/wikipedia.py
--- a/contrib_bots/bots/wikipedia/wikipedia.py
+++ b/contrib_bots/bots/wikipedia/wikipedia.py
@@ -60,12 +60,12 @@
             logging.error('unsuccessful data')
             return
 
-        search_string = data.json()['query']['search'][0]['title'].replace(' ', '_')
-        url = 'https://wikipedia.org/wiki/' + search_string
         new_content = 'For search term "' + query
         if len(data.json()['query']['search']) == 0:
             new_content = 'I am sorry. The search term you provided is not found :slightly_frowning_face:'
         else:
+            search_string = data.json()['query']['search'][0]['title'].replace(' ', '_')
+            url = 'https://en.wikipedia.org/wiki/' + search_string
             new_content = new_content + '", ' + url
 
         client.send_message(dict(

{"golden_diff": "diff --git a/contrib_bots/bots/wikipedia/wikipedia.py b/contrib_bots/bots/wikipedia/wikipedia.py\n--- a/contrib_bots/bots/wikipedia/wikipedia.py\n+++ b/contrib_bots/bots/wikipedia/wikipedia.py\n@@ -60,12 +60,12 @@\n             logging.error('unsuccessful data')\n             return\n \n-        search_string = data.json()['query']['search'][0]['title'].replace(' ', '_')\n-        url = 'https://wikipedia.org/wiki/' + search_string\n         new_content = 'For search term \"' + query\n         if len(data.json()['query']['search']) == 0:\n             new_content = 'I am sorry. The search term you provided is not found :slightly_frowning_face:'\n         else:\n+            search_string = data.json()['query']['search'][0]['title'].replace(' ', '_')\n+            url = 'https://en.wikipedia.org/wiki/' + search_string\n             new_content = new_content + '\", ' + url\n \n         client.send_message(dict(\n", "issue": "Wikipedia bot crashes when the query contains multiple word delimit by underscore.\nThe bot is under `contrib_bots/bots`.  Some error handling is needed.\n", "before_files": [{"content": "from __future__ import absolute_import\nfrom __future__ import print_function\nimport requests\nimport logging\n\n# See readme.md for instructions on running this code.\n\nclass WikipediaHandler(object):\n    '''\n    This plugin facilitates searching Wikipedia for a\n    specific key term and returns the top article from the\n    search. It looks for messages starting with '@wikipedia'\n     or '@wiki'.\n\n    In this example, we write all Wikipedia searches into\n    the same stream that it was called from, but this code\n    could be adapted to write Wikipedia searches to some\n    kind of external issue tracker as well.\n    '''\n\n    def usage(self):\n        return '''\n            This plugin will allow users to directly search\n            Wikipedia for a specific key term and get the top\n            article that is returned from the search. Users\n            should preface searches with \"@wikipedia\" or\n            \"@wiki\".\n            '''\n\n    def triage_message(self, message, client):\n        original_content = message['content']\n\n        # This next line of code is defensive, as we\n        # never want to get into an infinite loop of posting Wikipedia\n        # searches for own Wikipedia searches!\n        if message['sender_full_name'] == 'wikipedia-bot':\n            return False\n        is_wikipedia = (original_content.startswith('@wiki') or\n                        original_content.startswith('@wikipedia'))\n\n        return is_wikipedia\n\n    def handle_message(self, message, client, state_handler):\n        query = message['content']\n\n        for prefix in ['@wikipedia', '@wiki']:\n            if query.startswith(prefix):\n                query = query[len(prefix)+1:]\n                break\n\n        query_wiki_link = ('https://en.wikipedia.org/w/api.php?action=query&'\n                           'list=search&srsearch=%s&format=json' % (query,))\n        try:\n            data = requests.get(query_wiki_link)\n        except requests.exceptions.RequestException:\n            logging.error('broken link')\n            return\n\n        if data.status_code != 200:\n            logging.error('unsuccessful data')\n            return\n\n        search_string = data.json()['query']['search'][0]['title'].replace(' ', '_')\n        url = 'https://wikipedia.org/wiki/' + search_string\n        new_content = 'For search term \"' + query\n        if len(data.json()['query']['search']) == 0:\n            new_content = 'I am sorry. The search term you provided is not found :slightly_frowning_face:'\n        else:\n            new_content = new_content + '\", ' + url\n\n        client.send_message(dict(\n            type=message['type'],\n            to=message['display_recipient'],\n            subject=message['subject'],\n            content=new_content,\n        ))\n\nhandler_class = WikipediaHandler\n", "path": "contrib_bots/bots/wikipedia/wikipedia.py"}], "after_files": [{"content": "from __future__ import absolute_import\nfrom __future__ import print_function\nimport requests\nimport logging\n\n# See readme.md for instructions on running this code.\n\nclass WikipediaHandler(object):\n    '''\n    This plugin facilitates searching Wikipedia for a\n    specific key term and returns the top article from the\n    search. It looks for messages starting with '@wikipedia'\n     or '@wiki'.\n\n    In this example, we write all Wikipedia searches into\n    the same stream that it was called from, but this code\n    could be adapted to write Wikipedia searches to some\n    kind of external issue tracker as well.\n    '''\n\n    def usage(self):\n        return '''\n            This plugin will allow users to directly search\n            Wikipedia for a specific key term and get the top\n            article that is returned from the search. Users\n            should preface searches with \"@wikipedia\" or\n            \"@wiki\".\n            '''\n\n    def triage_message(self, message, client):\n        original_content = message['content']\n\n        # This next line of code is defensive, as we\n        # never want to get into an infinite loop of posting Wikipedia\n        # searches for own Wikipedia searches!\n        if message['sender_full_name'] == 'wikipedia-bot':\n            return False\n        is_wikipedia = (original_content.startswith('@wiki') or\n                        original_content.startswith('@wikipedia'))\n\n        return is_wikipedia\n\n    def handle_message(self, message, client, state_handler):\n        query = message['content']\n\n        for prefix in ['@wikipedia', '@wiki']:\n            if query.startswith(prefix):\n                query = query[len(prefix)+1:]\n                break\n\n        query_wiki_link = ('https://en.wikipedia.org/w/api.php?action=query&'\n                           'list=search&srsearch=%s&format=json' % (query,))\n        try:\n            data = requests.get(query_wiki_link)\n        except requests.exceptions.RequestException:\n            logging.error('broken link')\n            return\n\n        if data.status_code != 200:\n            logging.error('unsuccessful data')\n            return\n\n        new_content = 'For search term \"' + query\n        if len(data.json()['query']['search']) == 0:\n            new_content = 'I am sorry. The search term you provided is not found :slightly_frowning_face:'\n        else:\n            search_string = data.json()['query']['search'][0]['title'].replace(' ', '_')\n            url = 'https://en.wikipedia.org/wiki/' + search_string\n            new_content = new_content + '\", ' + url\n\n        client.send_message(dict(\n            type=message['type'],\n            to=message['display_recipient'],\n            subject=message['subject'],\n            content=new_content,\n        ))\n\nhandler_class = WikipediaHandler\n", "path": "contrib_bots/bots/wikipedia/wikipedia.py"}]}