2021年3月17日星期三

When I use scrapy's pipeline for data persistence, pymysql prompts'NoneType' object has no attribute'close' when I want to close the connection

When I use scrapy's pipeline for data persistence, pymysql prompts'NoneType' object has no attribute'close' when I want to close the connection

class mysqlpileplan(object):      conn = None      cursor = None      def open_spider(self,spider):          self.conn = pymysql.Connect(host='127.0.0.1',port=3306,user='root',password='qmyx233',db='pc_1',charset='utf8')          # print(self.conn)      def process_iteams(self,item,spider):          self.cursor = self.conn.cursor()          try:              self.cursor.execute('insert into qiubai values ("%s","%s")'%(item["src_name"],item["dt_list"]))              self.conn.commit()          except Exception as e:              print(e)              self.conn.rollback()          return item      def close_spider(self,spider):          try:                print(self.conn.close())                print(self.cursor.close())          except Exception as e:              print(e)    
https://stackoverflow.com/questions/66683412/when-i-use-scrapys-pipeline-for-data-persistence-pymysql-promptsnonetype-obj March 18, 2021 at 09:07AM

没有评论:

发表评论