Reputation: 193
Basically, I'm using an API and sending requests to it. The response doesn't come in json, so I am not being able to read it properly.
The response comes "plain":
RANDO:284420457:79065331589
What I have tried was the r.text()
but haven't been able to make it still work. Basically I'd like to have the information splitted by the :
and each of them going into a different variable.
r = requests.get(url=URL, verify=False)
data = r.text()
data = data.split(":")
var0 = data[0]
var1 = data[1]
var2 = data[2]
var0 would be RANDO
var1 284420457
var2 79065331589
Error at r.text(): Command raised an exception: TypeError: 'str' object is not callable
Upvotes: 2
Views: 1252
Reputation: 2302
Maybe something like this (note it's r.text
not r.text()
):
r = requests.get(url=URL, verify=False)
data = r.text
vars = {'var'+str(i): value for i, value in enumerate(data.split(":"))}
print(vars)
Output:
{'var0': 'RANDO', 'var1': '284420457', 'var2': '79065331589'}
Upvotes: 2