简体   繁体   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)

This should work这应该工作

data = json.loads(response.text)

It will return a data dictionary.它将返回一个data字典。 Check out this question for more details.查看此问题了解更多详情。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试加载测试Yaml数据时,“字符串索引必须为整数” - “string indices must be integers” when trying to load test yaml data TypeError:字符串索引必须是整数 Django - TypeError: String indices must be intergers Django 尝试从 json 文件访问数据时出现错误“TypeError: list indices must be integers or slice, not str”,python - Error "TypeError: list indices must be integers or slices, not str" occurs when trying to access data from a json file, with python TypeError:尝试使用Python从API提取数据时,字符串索引必须为整数 - TypeError: string indices must be integers when trying to extract data from an API using Python 当我尝试在for循环中调用特定数据时,错误提示:列表索引必须是整数或切片,而不是元组 - When I try to call out specific data in a for loop The error says: list indices must be integers or slices, not tuple 打印特定记录-错误消息说字符串索引必须是整数 - Printing specific records - error message says String indices must be integer 当我尝试使用函数参数作为列表索引时,出现错误“列表索引必须是整数或切片,而不是元组” - Error “list indices must be integers or slices, not tuple” occurs when I try to use function parametrs as list indices Django-获取coinmarketcap专业api结果为“字符串索引必须为整数” - Django - fetch coinmarketcap pro api results in “string indices must be integers” 我正在尝试从具有 100 个结果限制的 Api 获取数据,但是在使用时间戳更进一步时出现问题 - Im trying to get data from an Api with 100 results limit but im getting an issue when using timestamps to go further 尝试从api中提取时,Python错误“列表索引必须是整数,而不是str” - Python error 'list indices must be integers, not str' when trying to pull from api
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM