简体   繁体   中英

Error occurs when im trying to load the api results to the variable "data" it says string indices must be intergers

import requests
import json

input = input(" put you data here: ")
url = "https://breachdirectory.p.rapidapi.com/"

querystring = {"func":"auto","term":input}

headers = {
    'x-rapidapi-host': "breachdirectory.p.rapidapi.com",
    'x-rapidapi-key': "cdc2ac9cf2msh13a3dv713de3c61p1185f5jsncd225a72c5e1"
    }

response = requests.request("GET", url, headers=headers, params=querystring)

print(response.text)

data = str(json.loads(response.text))

print(' this is data value' + data)

This should work

data = json.loads(response.text)

It will return a data dictionary. Check out this question for more details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM