1

I am working with an API and everything "works" but it comes back as the following

    with requests.Session() as s:

        resp = s.post(url, json={"user": "s153152","password": "password123"}, headers=headers, verify=False)
        print(resp.status_code)

        timestamp = None
        deleteData = False
        fields = None

        resp2 = s.post(url2, json={
            "timestamp" : timestamp,
            "deleteData" : deleteData,
            "fields":fields}, headers=headers2, verify=False, timeout=45)

        resp2 = resp2.text
        print(type(resp2))
        for data in resp['hostName']:
            print(data)

resp2 is a string, it is possible to convert the output to a dictionary?

Expection: Json output so that i can call each individual value from key/pair

When i try the following i am getting jsondecode error:

resp3 = resp2.text
data = json.loads(resp3)
print(data)
print(type(resp2))
for i in data['hostName']:
    print(i)

json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Expected data to be returned, however the format of the variable is a string

[")]}',", ' { "newestTimestamp": "2016-08-29T13:43:59.0000001", "data": [ { "hostName": "MULBERRY", "ipAddresses": [ "192.168.146.131" ], "locationsWithMatches": "538", "locationsWithUnprotectedMatches": "93", "totalMatches": "9706", "totalUnprotectedMatches": "1319", "lastSearchTime": "2015-08-11T18:59:45.927", "id": -2147479361, "changedTimestamp": "2015-08-11T18:59:45.927", "dataTypes": [ { "count": 914, "name": "Social Security Number" }, { "count": 1237, "name": "Credit Card Number" } ] }, { "hostName": "DYCKMAN", "ipAddresses": [ "192.168.124.184" ], "locationsWithMatches": "592", "locationsWithUnprotectedMatches": "93", "totalMatches": "11470", "totalUnprotectedMatches": "1782", "lastSearchTime": "2015-08-31T05:53:05.28", "id": -2147479360, "changedTimestamp": "2015-08-31T05:53:05.28", "dataTypes": [ { "count": 955, "name": "Social Security Number" }, { "count": 555, "name": "Credit Card Number" }, "classifications": [ { "count": 24, "name": "Confidential" }, { "count": 12, "name": "PII" } ] }] }

0 Answers0