Reputation: 3
Im getting data from an API. Then i want to replace the value in the string from "True" to "Online".
request = requests.get("https://api.cleanvoice.ru/ts3/?address=xxxxxxxxxxx")
request_text = request.text
data = json.loads(request_text)
status = data["can_connect"]
onoff = status.replace("True","Online")
The error i get from replace() is AttributeError: 'bool' object has no attribute 'replace'
I want to implement a Teamspeak Online Checker by getting the value if the server is online of some russian api. That by the way, works perfectly fine.
Im working on Python 3.7.6
Upvotes: 0
Views: 79
Reputation: 3
I completely forgot that the value is a boolean value so i just added a if statement like paxdiablo wrote.
if status is True:
print('Its online')
elif status is False:
print('Its offline')
Upvotes: 0
Reputation: 882028
The status
variable appears to be a boolean one, as evidenced by the error:
AttributeError: 'bool' object has no attribute 'replace'
You therefore should be able to just use something like:
onoff = "online" if status else "offline"
Upvotes: 1