0
我很抱歉,如果這是一個基本的修復和帖子的長度,但我是Python的新手。爲了上下文的目的,我還包含了大量的腳本。Python - 字符串索引必須是整數
我正在使用腳本將掃描數據從JSON拖放到MySQL DB中。該腳本工作正常,直到更新發布。
現在,當我運行該腳本我收到錯誤:
的結果resultc [「響應」] [「結果」]: 類型錯誤:字符串索引必須是整數
此更新我之前知道每個值的數據類型,但這已經改變,我無法確定在哪裏。有沒有辦法將每個值轉換爲字符串被識別?
# 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"]))
錯誤是告訴你,'resultc [「響應」]'是一個'String',你不能引用它的'results'索引(因爲字符串在技術上是一個字符元組)。請發佈'print(resultc)'的輸出。 – 2013-02-14 22:22:17
我會在早上發佈輸出,謝謝。 – Ben 2013-02-14 22:25:29
試圖找到您的列表,然後找到一個整數索引它。 – monkut 2013-02-14 22:32:02