0

I apologize if this is a basic fix and the length of the post, but I am new to 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. 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

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"]))
5
  • The error is telling you that resultc['response'] is a String and that you cannot reference the results index of it (because strings are technically a tuple of characters). Please post the output of print(resultc) Commented Feb 14, 2013 at 22:22
  • I will post the output in the morning, thank you. Commented Feb 14, 2013 at 22:25
  • try to find your list and then find an integer to index it with. Commented Feb 14, 2013 at 22:32
  • Response "{'status': '200', 'content-length': '239', 'expires': 'Thu, 19 Nov 1981 08:52:00 GMT', 'server': 'Apache', 'pragma': 'no-store', 'cache-control': 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0', 'date': 'Fri, 15 Feb 2013 15:11:41 GMT', 'content-type': 'application/json'}" Conetnt "{"type":"regular","request_id":"1","response":"","error_code":146,"error_msg":"Invalid parameters specified for vuln query.\nFilter 'lastSeen' must be in the following format: <end day>:<start day>.\n","warnings":[],"timestamp":1360941101}" <type 'dict'> <type 'unicode'> Commented Feb 15, 2013 at 15:32
  • There was quite a bit of data before that but it is too much to post Commented Feb 15, 2013 at 15:32

1 Answer 1

1

Put this before the for loop to work out which object is the string (I guess it's probably the second one)

print type(resultc)
print type(resultc['response'])
Sign up to request clarification or add additional context in comments.

1 Comment

I will try this in the morning and post the result, my server got shutdown for maintenance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.