I'm trying to put actively some datas from a list to my database in the table polls_ip. However it seems to be some problems of arguments maybe owing the type of the data I want to put inside.
If you want to have a look of the usefull part of my code:
fin_flag = ( tcp.flags & dpkt.tcp.TH_FIN ) != 0
rst_flag = ( tcp.flags & dpkt.tcp.TH_RST ) != 0
if fin_flag or rst_flag:
src_ip2 = socket.inet_ntoa(ip.src)
dst_ip2 = socket.inet_ntoa(ip.dst)
for element in liste:
if element == (src_ip2+" "+dst_ip2) or element == (dst_ip2+" "+src_ip2):
liste.remove(element)
cursor.execute("INSERT INTO polls_ip (Ip) VALUES (%s)", (element))
The problem probably come from the line inside cursor.execute
Have a look at the output:
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner
self.run()
File "scriptbdd.py", line 134, in run
self.p.dispatch(0, PieceRequestSniffer.cb)
File "scriptbdd.py", line 120, in cb
cursor.execute("INSERT INTO polls_ip (Ip) VALUES (%s)", (element))
File "/usr/lib/pymodules/python2.7/mysql/connector/cursor.py", line 310, in execute
"Wrong number of arguments during string formatting")
ProgrammingError: Wrong number of arguments during string formatting
And even with a coma in (element,)), another problem is raised:
root@debian:/home/florian/Documents/mysite/polls# python scriptbdd.py
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner
self.run()
File "scriptbdd.py", line 132, in run
self.p.dispatch(0, PieceRequestSniffer.cb)
File "scriptbdd.py", line 120, in cb
cursor.execute("INSERT INTO polls_ip (Ip) VALUES (%s)", (element,))
File "/usr/lib/pymodules/python2.7/mysql/connector/cursor.py", line 314, in execute
res = self.db().protocol.cmd_query(stmt)
InterfaceError: Failed executing the operation; 'NoneType' object has no attribute 'cmd_query'