1
저는 잠시 동안이 벽에 머리를 부딪 혔습니다. 이 삽입 쿼리를 사용할 수 없습니다. 여러 데이터 유형 (int, bool, strings, NoneType)을 가지고 있기 때문에 삽입하고 있는데 %s
을 사용하고 있습니까? 어떤 도움이라도 대단히 감사하겠습니다. 감사!pymysql : TypeError : 문자열 형식화 중에 모든 인수가 변환되지 않습니다.
values = [None, '1.1.1.15', '2.2.2.2', 15, 1, 'hax', 'NULL', 'need to build this', False, 'NULL', 'NULL', 'NULL']
오류 :
class DBWork(object):
def __init__(self, attackerip=None, victimip=None, shunlen=15, shuncount=1, shunreason=None, shunepoch=None,
shunerrorbool=False, shunerror=None, paloaddedepoch=None, paloremovedepoch=None,
lastshunlen=15):
self.Id = None
self.attackerip = attackerip
self.victimip = victimip
self.shunlen = shunlen
self.shuncount = shuncount
self.shunreason = shunreason
self.shunepoch = shunepoch
self.shundatetime = 'need to build this'
self.shunerrorbool = shunerrorbool
self.shunerror = shunerror
self.paloaddedepoch = paloaddedepoch
self.paloremovedepoch = paloremovedepoch
self.lastshunlen = lastshunlen
self.shunlen = shunlen
self.newshunlen = lastshunlen * shuncount
def HistoryInsert(self):
insert_query = (
"INSERT INTO `autoshun`.`shunhistory` "
"(Id, attackerip, victimip, shunlen, shuncount, shunreason, shunepoch, shundatetime, shunerrorbool, "
"shunerror, paloaddedepoch, paloremovedepoch) "
"VALUES "
"(NULL, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s);"
)
values = [None, self.attackerip, self.victimip, self.shunlen, self.shuncount, self.shunreason, self.shunepoch,
self.shundatetime, self.shunerrorbool, self.shunerror, self.paloaddedepoch, self.paloremovedepoch]
print values
self.cur.execute(insert_query, values)
sample = DBWork(attackerip='1.1.1.15', victimip='2.2.2.2', shunlen=15, shuncount=1, shunreason='hax', shunerrorbool=True)
sample.DBConnect()
sample.HistoryInsert()
값에 전달되는
Traceback (most recent call last):
File "/home/dobbs/PycharmProjects/autoshun/sqlobjects.py", line 102, in <module>
sample.HistoryInsert()
File "/home/dobbs/PycharmProjects/autoshun/sqlobjects.py", line 95, in HistoryInsert
self.cur.execute(insert_query, values)
File "/usr/lib64/python2.7/site-packages/pymysql/cursors.py", line 164, in execute
query = self.mogrify(query, args)
File "/usr/lib64/python2.7/site-packages/pymysql/cursors.py", line 143, in mogrify
query = query % self._escape_args(args, conn)
TypeError: not all arguments converted during string formatting
고맙습니다. 그게 분명했습니다. – dobbs
건배, 친구. 당신에게 행복한 코딩! – bernie