Reputation: 61
I'm using request library for parsing data, it returning list of json data when im trying to find the length of response list it giving error TypeError: object of type 'Response' has no len() im using this method
import requests
r=requests.get('http://localhost:3000/api/Customer')
print(r.status_code)
print(r.text)
x={}
for i in range(0,len(r)):
x = r.json()[i]
print(x)
by using this im getting error TypeError: object of type 'Response' has no len()
Upvotes: 3
Views: 2896
Reputation: 106553
You should use len
on the list object returned by r.json()
instead:
lst = r.json()
for i in range(len(lst)):
x = lst[i]
print(x)
But then you should simply iterate over the list instead:
for x in r.json():
print(x)
Upvotes: 2