Http Response Python

Viewed 23

like the response.json() does not display anything but on the other hand the response.text displays the results how to loop through response.text Exemple de mon code

def api:
  url = 'http://api-content/product/GetProduct'
  x = requests.get(url)
  content=x.text

"produits":[{
    "des":"blaa",
     "cont":"sdf"
 }]

Merci de votre aide

1 Answers

I always do json.loads(x.text) and that seems to work for me

def api:
  url = 'http://api-content/product/GetProduct'
  x = requests.get(url)
  import json
  r = json.loads(x.text)
  for i in r:
      print(i)
Related