I am working with some data and building a list of queries based upon what incident_source. This was working fine when I didn't have variable added to it which requires the + symbols. When I added that I am getting: TypeError: can only concatenate str (not "list") to str. Does anyone know a way around this or a better solution?
source = 1
offense_id = [122,153,142]
incident_source = ['source_1', 'source_2']
num_searches_by_id = []
queries_needed_ran = []
for i,j in zip(incident_source, offense_id):
if i == 'source_1':
data = ['''SELECT QIDNAME(qid) AS 'Event Name',"Request Method" FROM events WHERE URL=REPLACEFIRST('hxxp',''' + "'" + source + "'" + ''','http') START ''' + str(start_time) + '''-43200000''',
'''select QIDNAME(qid) as 'Event Name', "Recepient" from events where ( "URL"=''' + "'" + str(source) + "'" + '''AND logSourceId='1' ) START ''' + str(start_time) + '''-43200000''']
num_searches_by_id.append(len(data))
for x in data:
queries_needed_ran.append(x)
elif i == 'source_2':
data = ['''select QIDNAME(qid) as 'Event Name', "Recepient" from events where ( "URL"=''' + "'" + str(source) + "'" + '''AND logSourceId='1' ) START ''' + str(start_time) + '''-43200000''']
num_searches_by_id.append(len(data))
for x in data:
queries_needed_ran.append(x)
else:
num_searches_by_id.append(0)
runfile('/Users/thomas.gorman/Documents/Python Connectors/riskiq_passivetotal/untitled20.py', wdir='/Users/thomas.gorman/Documents/Python Connectors/riskiq_passivetotal')
Traceback (most recent call last):
File "/Users/me/Documents/Python Connectors/untitled20.py", line 427, in <module>
data = ['''SELECT QIDNAME(qid) AS 'Event Name',"Request Method" FROM events WHERE URL=REPLACEFIRST('hxxp',''' + "'" + source + "'" + ''','http') START ''' + str(start_time) + '''-43200000''',
TypeError: can only concatenate str (not "list") to str`
Expected output:
num_searches_by_id = ['''SELECT QIDNAME(qid) AS 'Event Name',"Request Method" FROM events WHERE URL=REPLACEFIRST('hxxp',''' + "'" + source + "'" + ''','http') START ''' + str(start_time) + '''-43200000''',
'''select QIDNAME(qid) as 'Event Name', "Recepient" from events where ( "URL"=''' + "'" + str(source) + "'" + '''AND logSourceId='1' ) START ''' + str(start_time) + '''-43200000''',
'''select QIDNAME(qid) as 'Event Name', "Recepient" from events where ( "URL"=''' + "'" + str(source) + "'" + '''AND logSourceId='1' ) START ''' + str(start_time) + '''-43200000''']
source? And what is your expected output?sourceto indicate thesourcespecified in the list. You can access this viaiwhich you defined in the opening of your loop.