我TypeError: 'str' object is not callable
在
INSERT INTO database
.
我正在使用:Python 2.7.5、Scrapy 0.18 和数据库 MySQL
我的追溯是:
Traceback (most recent call last):
File "C:\python27\lib\threading.py", line 781, in __bootstrap
self.__bootstrap_inner()
File "C:\python27\lib\threading.py", line 808, in __bootstrap_inner
self.run()
File "C:\python27\lib\threading.py", line 761, in run self.__target(*self.__args, **self.__kwargs)
--- <exception caught here> ---
File "C:\python27\lib\site-packages\twisted\python\threadpool.py", line 191, in _worker
result = context.call(ctx, function, *args, **kwargs)
File "C:\python27\lib\site-packages\twisted\python\context.py", line 118, in callWithContext
return self.currentContext().callWithContext(ctx, func, *args, **kw)
File "C:\python27\lib\site-packages\twisted\python\context.py", line 81, in callWithContext
return func(*args,**kw)
File "C:\python27\lib\site-packages\twisted\enterprise\adbapi.py", line 448, in _runInteraction
result = interaction(trans, *args, **kw)
File "apple\pipelines.py", line 49, in _conditional_insert
'INSERT INTO job (id, company, day, hour, job, car1, car2) values (%s, %s, %s, %s, %s, %s)' ("company, day, hour, job, car1, car2 ")
exceptions.TypeError: 'str' object is not callable
这是我的代码脚本:
def _conditional_insert(self, tx, item):
# create record if doesn't exist.
# all this block run on it's own thread
tx.execute('select * from job where hour = %s', ("item['hour'], "))
result = tx.fetchone()
if result:
log.msg("Item already stored in db: %s" % item, level=log.DEBUG)
else:
tx.execute(\
'INSERT INTO job (id, company, day, hour, job, car1, car2) values (%s, %s, %s, %s, %s, %s)' ("company, day, hour, job, car1, car2 ")
)
log.msg("Item stored in db: %s" % item, level=log.DEBUG)
def handle_error(self, e):
log.err(e)
知道我能做些什么来解决这个错误吗?