dimanche 2 août 2020

How do I get my JSON decoder to work properly?

I was working on API testing, and I tried everything but it would not print the JSON file into a string. I was wondering if it was the website I was testing the API requests from as I kept getting a 406 error. I even tried taking code from online that shows how to do this but it still would not print and it would give the error listed below. Here I give the code I used and the response Pycharm's console gave me.

import json
import requests

res = requests.get("http://dummy.restapiexample.com/api/v1/employees")
data = json.loads(res.text)
data = json.dumps(data)
print(data)
print(type(data))

Traceback (most recent call last):
  File "C:/Users/johnc/PycharmProjects/API_testing/api_testing.py", line 8, in <module>
    data = json.loads(res.text)
  File "D:\Program Files (x86)\lib\json\__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "D:\Program Files (x86)\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "D:\Program Files (x86)\lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)






                     

Aucun commentaire:

Enregistrer un commentaire