将python采集解析的数据存入数据库中报错。

我的代码是:

判定是否目标url

if self.isGoalUrl():
try:
print(‘is goal url’)
t = threading.Thread(target = self.collectMessage,args=(soup,self.sqlconn))
t.setDaemon(False)
t.start()
except Exception as e:
print(e)

在collectMessage函数中调用数据库插入操作

def insert_table(self,id,conType,text,startUrl,currentUrl):

sql = ‘insert into T_SC_CONTENT(id,con_type,con_text,start_url,current_url,deal_date,deal_client) values (“{0}”,”{1}”,”{2}”,”{3}”,”{4}”,sysdate(),”c1″)’.format(id,conType,text,startUrl,currentUrl)

print(sql)
self.cursor.execute(sql)
self.cnx.commit()

插入几百条之后就会几个错误:

Exception in thread Thread-584:
Traceback (most recent call last):
File “C:Python34libthreading.py”, line 911, in _bootstrap_inner
self.run()
File “C:Python34libthreading.py”, line 859, in run
self._target(*self._args, **self._kwargs)
File “D:workspacencnetspiderslaveslavecollect_url.py”, line 111, in collectMeaasge
sqlconn.insert_table(id,conType,text,self.startUrl,self.currentUrl)
File “D:workspacencnetspiderslavemysqlsqltables.py”, line 71, in insert_table
self.cnx.commit()
File “C:Python34libsite-packagesmysqlconnectorconnection.py”, line 850, in commit
self._execute_query(“COMMIT”)
File “C:Python34libsite-packagesmysqlconnectorconnection.py”, line 869, in _execute_query
self.cmd_query(query)
File “C:Python34libsite-packagesmysqlconnectorconnection.py”, line 488, in cmd_query
result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query))
File “C:Python34libsite-packagesmysqlconnectorconnection.py”, line 384, in _handle_result
elif packet[4] == 0:
IndexError: bytearray index out of range

我把报错的sql放入mysql命令框里执行,可以正常插入。请问大神这是什么原因啊啊啊啊

2 收藏


直接登录
最新评论