[英]Python - string indices must be integers
I apologize if this is a basic fix and the length of the post, but I am new to Python. 抱歉,这是基本修复方法,也不涉及发布时间,但我是Python新手。 I've also included a large chunk of the script for context purposes.
为了上下文的目的,我还包含了很大一部分脚本。
I am using a script to pull scanning data from JSON into a MySQL DB. 我正在使用脚本将扫描数据从JSON拉入MySQL数据库。 The script was working fine until an update was released.
在发布更新之前,脚本运行良好。
Now when I run the script I receive the error: 现在,当我运行脚本时,我收到错误消息:
for result in resultc['response']['results']: TypeError: string indices must be integers 对于resultc ['response'] ['results']中的结果:TypeError:字符串索引必须为整数
Before this update I knew the data types for each value, but this has changed and I cannot pinpoint where. 在此更新之前,我知道每个值的数据类型,但这已经更改,并且我无法查明位置。 Is there a way to convert each value to be recognized as a string?
有没有一种方法可以将每个值转换为字符串?
# 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"]))
Put this before the for loop to work out which object is the string (I guess it's probably the second one) 将其放在for循环之前可以确定哪个对象是字符串(我想可能是第二个对象)
print type(resultc)
print type(resultc['response'])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.