Reputation: 3
I've been working on a bot for Discord
in discord.py
(not related) and I'm trying to pull from a server so I can interpret it, however, I'm getting a
BAD REQUEST 400
when trying to actually pull from the server. I've tried to add a header to specify it as a JSON but it won't work.
await bot.say("Fetching data")
headers = {"Content-type": "application/json"}
url = 'http://jisho.org/api/v1/search/words?keyword=boushi'
response = requests.get(url, headers=headers).json()
await bot.say(response)
The bot.say
is just repeating back to me the output.
Upvotes: 0
Views: 1053
Reputation: 284
I wouldn't use .json() at the end of the request, in case you want to check the status_code for a bad request first.
response = requests.get(url, headers=headers)
if response.status_code == 200:
print response.content
And if you want to do something with the dict you can use json.loads()
foo = json.loads(response.content)
Upvotes: 2