stack_overflow: Pass API query parameters as `params` dict in requests.get().
MODIFY
zulip_bots/zulip_bots/bots/stack_overflow/fixtures/test_incorrect_query.json
zulip_bots/zulip_bots/bots/stack_overflow/fixtures/test_incorrect_query.json
{
"request": {
- "api_url":"http://api.stackexchange.com/2.2/search/advanced?order=desc&sort=relevance&site=stackoverflow&title=narendra"
+ "api_url":"http://api.stackexchange.com/2.2/search/advanced",
+ "params": {
+ "order": "desc",
+ "sort": "relevance",
+ "site": "stackoverflow",
+ "title": "narendra"
+ }
},
"response": {
"data": {

MODIFY
zulip_bots/zulip_bots/bots/stack_overflow/fixtures/test_multi_word.json
zulip_bots/zulip_bots/bots/stack_overflow/fixtures/test_multi_word.json
{
"request": {
- "api_url":"http://api.stackexchange.com/2.2/search/advanced?order=desc&sort=relevance&site=stackoverflow&title=what%20is%20flutter"
+ "api_url":"http://api.stackexchange.com/2.2/search/advanced",
+ "params": {
+ "order": "desc",
+ "sort": "relevance",
+ "site": "stackoverflow",
+ "title": "what is flutter"
+ }
},
"response": {
"data": {

MODIFY
zulip_bots/zulip_bots/bots/stack_overflow/fixtures/test_number_query.json
zulip_bots/zulip_bots/bots/stack_overflow/fixtures/test_number_query.json
{
"request": {
- "api_url":"http://api.stackexchange.com/2.2/search/advanced?order=desc&sort=relevance&site=stackoverflow&title=113"
+ "api_url":"http://api.stackexchange.com/2.2/search/advanced",
+ "params": {
+ "order": "desc",
+ "sort": "relevance",
+ "site": "stackoverflow",
+ "title": "113"
+ }
},
"response": {
"data": {

MODIFY
zulip_bots/zulip_bots/bots/stack_overflow/fixtures/test_single_word.json
zulip_bots/zulip_bots/bots/stack_overflow/fixtures/test_single_word.json
{
"request": {
- "api_url":"http://api.stackexchange.com/2.2/search/advanced?order=desc&sort=relevance&site=stackoverflow&title=restful"
+ "api_url":"http://api.stackexchange.com/2.2/search/advanced",
+ "params": {
+ "order": "desc",
+ "sort": "relevance",
+ "site": "stackoverflow",
+ "title": "restful"
+ }
},
"response": {
"data": {

MODIFY
zulip_bots/zulip_bots/bots/stack_overflow/fixtures/test_status_code.json
zulip_bots/zulip_bots/bots/stack_overflow/fixtures/test_status_code.json
{
"request": {
- "api_url":"http://api.stackexchange.com/2.2/search/advanced?order=desc&sort=relevance&site=stackoverflow&title=Zulip"
+ "api_url":"http://api.stackexchange.com/2.2/search/advanced",
+ "params": {
+ "order": "desc",
+ "sort": "relevance",
+ "site": "stackoverflow",
+ "title": "Zulip"
+ }
},
"response": {
"data": {

MODIFY
zulip_bots/zulip_bots/bots/stack_overflow/stack_overflow.py
zulip_bots/zulip_bots/bots/stack_overflow/stack_overflow.py
@@ -45,11 +45,15 @@ class StackOverflowHandler(object):
if query == '' or query == 'help':
return help_text
- query_stack_link = ('http://api.stackexchange.com/2.2/search/advanced?'
- 'order=desc&sort=relevance&site=stackoverflow&title=%s'
- % (urllib.parse.quote(query),))
+ query_stack_url = 'http://api.stackexchange.com/2.2/search/advanced'
+ query_stack_params = dict(
+ order='desc',
+ sort='relevance',
+ site='stackoverflow',
+ title=query
+ )
try:
- data = requests.get(query_stack_link)
+ data = requests.get(query_stack_url, params=query_stack_params)
except requests.exceptions.RequestException:
logging.error('broken link')

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