wikipedia: Pass API query parameters as `params` dict in requests.get().
MODIFY
zulip_bots/zulip_bots/bots/wikipedia/fixtures/test_hash_query.json
zulip_bots/zulip_bots/bots/wikipedia/fixtures/test_hash_query.json
{
"request": {
- "api_url":"https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=%23&format=json"
+ "api_url":"https://en.wikipedia.org/w/api.php",
+ "params": {
+ "action": "query",
+ "list": "search",
+ "srsearch": "#",
+ "format": "json"
+ }
},
"response": {
"data": {

MODIFY
zulip_bots/zulip_bots/bots/wikipedia/fixtures/test_incorrect_query.json
zulip_bots/zulip_bots/bots/wikipedia/fixtures/test_incorrect_query.json
{
"request": {
- "api_url":"https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=sssssss%20kkkkk&format=json"
+ "api_url":"https://en.wikipedia.org/w/api.php",
+ "params": {
+ "action": "query",
+ "list": "search",
+ "srsearch": "sssssss kkkkk",
+ "format": "json"
+ }
},
"response": {
"data": {

MODIFY
zulip_bots/zulip_bots/bots/wikipedia/fixtures/test_multi_word.json
zulip_bots/zulip_bots/bots/wikipedia/fixtures/test_multi_word.json
{
"request": {
- "api_url":"https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=The%20sky%20is%20blue&format=json"
+ "api_url":"https://en.wikipedia.org/w/api.php",
+ "params": {
+ "action": "query",
+ "list": "search",
+ "srsearch": "The sky is blue",
+ "format": "json"
+ }
},
"response": {
"data": {

MODIFY
zulip_bots/zulip_bots/bots/wikipedia/fixtures/test_number_query.json
zulip_bots/zulip_bots/bots/wikipedia/fixtures/test_number_query.json
{
"request": {
- "api_url":"https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=123&format=json"
+ "api_url":"https://en.wikipedia.org/w/api.php",
+ "params": {
+ "action": "query",
+ "list": "search",
+ "srsearch": "123",
+ "format": "json"
+ }
},
"response": {
"data": {

MODIFY
zulip_bots/zulip_bots/bots/wikipedia/fixtures/test_single_word.json
zulip_bots/zulip_bots/bots/wikipedia/fixtures/test_single_word.json
{
"request": {
- "api_url":"https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=happy&format=json"
+ "api_url":"https://en.wikipedia.org/w/api.php",
+ "params": {
+ "action": "query",
+ "list": "search",
+ "srsearch": "happy",
+ "format": "json"
+ }
},
"response": {
"data": {

MODIFY
zulip_bots/zulip_bots/bots/wikipedia/fixtures/test_status_code.json
zulip_bots/zulip_bots/bots/wikipedia/fixtures/test_status_code.json
{
"request": {
- "api_url":"https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=Zulip&format=json"
+ "api_url":"https://en.wikipedia.org/w/api.php",
+ "params": {
+ "action": "query",
+ "list": "search",
+ "srsearch": "Zulip",
+ "format": "json"
+ }
},
"response": {
"data": {

MODIFY
zulip_bots/zulip_bots/bots/wikipedia/wikipedia.py
zulip_bots/zulip_bots/bots/wikipedia/wikipedia.py
@@ -47,11 +47,15 @@ class WikipediaHandler(object):
if query == '':
return help_text
- query_wiki_link = ('https://en.wikipedia.org/w/api.php?action=query&'
- 'list=search&srsearch=%s&format=json'
- % (urllib.parse.quote(query),))
+ query_wiki_url = 'https://en.wikipedia.org/w/api.php'
+ query_wiki_params = dict(
+ action='query',
+ list='search',
+ srsearch=query,
+ format='json'
+ )
try:
- data = requests.get(query_wiki_link)
+ data = requests.get(query_wiki_url, params=query_wiki_params)
except requests.exceptions.RequestException:
logging.error('broken link')

wikipedia: Pass API query parameters as `params` dict in requests.get().