簡體   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