0

如果这是基本修复和帖子的长度,我深表歉意,但我是 Python 新手。出于上下文目的,我还包含了大部分脚本。

我正在使用脚本将扫描数据从 JSON 提取到 MySQL 数据库中。在发布更新之前,该脚本运行良好。

现在,当我运行脚本时,我收到错误:

结果在 resultc['response']['results']: TypeError: string indices must be integers

在此更新之前,我知道每个值的数据类型,但这已经改变,我无法确定在哪里。有没有办法将每个值转换为字符串?

# Send the cumulative JSON and then populate the table
cumresponse, content = SendRequest(url, headers, cumdata)
resultc = json.loads(content)
off = 0
print "\nFilling cumvulndata table with vulnerabilities from the cumulative database. Please wait..."
for result in resultc['response']['results']:
    off += 1
    print off, result
    cursor.execute ("""INSERT INTO cumvulndata(
offset,pluginName,repositoryID,
severity,pluginID,hasBeenMitigated,
dnsName,macAddress,familyID,recastRisk,
firstSeen,ip,acceptRisk,lastSeen,netbiosName,
port,pluginText,protocol) VALUES 

(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,(FROM_UNIXTIME(%s)),%s,%s,(FROM_UNIXTIME(%s)),%s,%s,    %s,%s)""" , (off,result["pluginName"],result["repositoryID"]),result["severity"]),
result["pluginID"]), result["hasBeenMitigated"]),result["dnsName"],
result["macAddress"],result["familyID"]),result["recastRisk"]),
result["firstSeen"],result["ip"],result["acceptRisk"],result["lastSeen"],
result["netbiosName"],result["port"],result["pluginText"],result["protocol"]))
4

1 回答 1

1

将其放在 for 循环之前以找出哪个对象是字符串(我猜它可能是第二个)

print type(resultc)
print type(resultc['response'])
于 2013-02-14T22:20:01.330 回答