繁体   English   中英

Python-字符串索引必须是整数

[英]Python - string indices must be integers

抱歉,这是基本修复方法,也不涉及发布时间,但我是Python新手。 为了上下文的目的,我还包含了很大一部分脚本。

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

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

对于resultc ['response'] ['results']中的结果:TypeError:字符串索引必须为整数

在此更新之前,我知道每个值的数据类型,但这已经更改,并且我无法查明位置。 有没有一种方法可以将每个值转换为字符串?

# 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"]))

将其放在for循环之前可以确定哪个对象是字符串(我想可能是第二个对象)

print type(resultc)
print type(resultc['response'])

暂无
暂无

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

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