So I'm trying to random generate an insult from an API. https://insult.mattbas.org/api/. I'm getting a response 200 from the API but I can't seem to extract data
I'm using this code:
def get_insult():
res = requests.get('https://insult.mattbas.org/api/insult.txt')
print(res)
data_json = json.loads(res.json())
print(data_json)
get_insult()
CodePudding user response:
This should work. You don't need to use json.loads()
as the response is not json
.
def get_insult():
res = requests.get('https://insult.mattbas.org/api/insult.txt')
data_json = res.text
print(data_json)
get_insult()