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

This commit is contained in:
novokrest 2018-05-12 08:17:04 +03:00 committed by Tim Abbott
parent 5ad5e11587
commit 65ebd6e595
8 changed files with 30 additions and 8 deletions

View file

@ -1,6 +1,9 @@
{ {
"request": { "request": {
"api_url": "https://yoda.p.mashape.com/yoda?sentence=You+will+learn+how+to+speak+like+me+someday.", "api_url": "https://yoda.p.mashape.com/yoda",
"params": {
"sentence": "You+will+learn+how+to+speak+like+me+someday."
},
"headers": { "headers": {
"X-Mashape-Key": "12345678", "X-Mashape-Key": "12345678",
"Accept": "text/plain" "Accept": "text/plain"

View file

@ -1,6 +1,9 @@
{ {
"request": { "request": {
"api_url": "https://yoda.p.mashape.com/yoda?sentence=you+still+have+much+to+learn", "api_url": "https://yoda.p.mashape.com/yoda",
"params": {
"sentence": "you+still+have+much+to+learn"
},
"headers": { "headers": {
"X-Mashape-Key": "12345678", "X-Mashape-Key": "12345678",
"Accept": "text/plain" "Accept": "text/plain"

View file

@ -1,6 +1,9 @@
{ {
"request": { "request": {
"api_url": "https://yoda.p.mashape.com/yoda?sentence=You+will+learn+how+to+speak+like+me+someday.", "api_url": "https://yoda.p.mashape.com/yoda",
"params": {
"sentence": "You+will+learn+how+to+speak+like+me+someday."
},
"headers": { "headers": {
"X-Mashape-Key": "12345678", "X-Mashape-Key": "12345678",
"Accept": "text/plain" "Accept": "text/plain"

View file

@ -1,6 +1,9 @@
{ {
"request": { "request": {
"api_url": "https://yoda.p.mashape.com/yoda?sentence=@#$%^&*", "api_url": "https://yoda.p.mashape.com/yoda",
"params": {
"sentence": "@#$%^&*"
},
"headers": { "headers": {
"X-Mashape-Key": "12345678", "X-Mashape-Key": "12345678",
"Accept": "text/plain" "Accept": "text/plain"

View file

@ -1,6 +1,9 @@
{ {
"request": { "request": {
"api_url": "https://yoda.p.mashape.com/yoda?sentence=23456", "api_url": "https://yoda.p.mashape.com/yoda",
"params": {
"sentence": "23456"
},
"headers": { "headers": {
"X-Mashape-Key": "12345678", "X-Mashape-Key": "12345678",
"Accept": "text/plain" "Accept": "text/plain"

View file

@ -1,6 +1,9 @@
{ {
"request": { "request": {
"api_url": "https://yoda.p.mashape.com/yoda?sentence=You+will+learn+how+to+speak+like+me+someday.", "api_url": "https://yoda.p.mashape.com/yoda",
"params": {
"sentence": "You+will+learn+how+to+speak+like+me+someday."
},
"headers": { "headers": {
"X-Mashape-Key": "12345678", "X-Mashape-Key": "12345678",
"Accept": "text/plain" "Accept": "text/plain"

View file

@ -1,6 +1,9 @@
{ {
"request": { "request": {
"api_url": "https://yoda.p.mashape.com/yoda?sentence=You+will+learn+how+to+speak+like+me+someday.", "api_url": "https://yoda.p.mashape.com/yoda",
"params": {
"sentence": "You+will+learn+how+to+speak+like+me+someday."
},
"headers": { "headers": {
"X-Mashape-Key": "12345678", "X-Mashape-Key": "12345678",
"Accept": "text/plain" "Accept": "text/plain"

View file

@ -55,7 +55,8 @@ class YodaSpeakHandler(object):
def send_to_yoda_api(self, sentence: str) -> str: def send_to_yoda_api(self, sentence: str) -> str:
# function for sending sentence to api # function for sending sentence to api
response = requests.get("https://yoda.p.mashape.com/yoda?sentence=" + sentence, response = requests.get("https://yoda.p.mashape.com/yoda",
params=dict(sentence=sentence),
headers={ headers={
"X-Mashape-Key": self.api_key, "X-Mashape-Key": self.api_key,
"Accept": "text/plain" "Accept": "text/plain"