Pawnyy
Pawnyy

Reputation: 1

Replace words from an API in python

I am using an API I found online for one of my scripts, and I am wondering if I can change one word from the API to something else. My code is:

import requests
people = requests.get('https://insult.mattbas.org/api/insult')

print("Welcome to the insult machine!\nType somebody you want to insult!")
b = input()

print(people.replace("You", b))

Is replace not a command? If so, what plugin and/or commands would I need to do it? Thanks!

Upvotes: 0

Views: 234

Answers (1)

Chris Johnson
Chris Johnson

Reputation: 22006

The value returned from requests.get isn’t a string, it’s a response object and that class has no replace method.

Have a look at the structure of that class. For example, you can do r = requests.get(...) and r.text.replace(...).

In other words, you need to operate on the text part of the response object.

Upvotes: 3

Related Questions