我正在处理一些数据,并根据incident_source
构建一个查询列表。当我没有添加需要+符号的变量时,它工作得很好。当我添加时,我得到:TypeError: can only concatenate str (not "list") to str
。有人知道解决这个问题的方法或更好的解决方案吗
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`
预期产出:
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''']
因此,我不确定您的一些变量以及它们来自何处,但我通过在
if
语句中为您要查找的索引放置括号并更改变量,从而消除了TypeError: can only concatenate str (not "list") to str
。也不确定start_time
来自哪里相关问题 更多 >
编程相关推荐