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

This commit is contained in:
novokrest 2018-05-11 07:52:09 +03:00 committed by Tim Abbott
parent a38917723a
commit 86ffbb2b4a
6 changed files with 43 additions and 9 deletions

View file

@ -1,6 +1,12 @@
{
"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": {

View file

@ -1,6 +1,12 @@
{
"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": {

View file

@ -1,6 +1,12 @@
{
"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": {

View file

@ -1,6 +1,12 @@
{
"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": {

View file

@ -1,6 +1,12 @@
{
"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": {

View file

@ -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')