簡體   English   中英

當我嘗試將 api 結果加載到變量“數據”時發生錯誤,它說字符串索引必須是整數

[英]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)

這應該工作

data = json.loads(response.text)

它將返回一個data字典。 查看此問題了解更多詳情。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM