MySQL資料庫報錯pymysql.err.InterfaceError: (0, '')

來源:互聯網
上載者:User

標籤:and   col   connect   線上   cti   art   cep   rate   span   

今天入庫的時候出現了報錯pymysql.err.InterfaceError: (0, ‘‘),經過排查,發現是由於把串連資料庫的代碼放到了插入函數的外部,導致多線程運行出錯

 1 def write_into_db(data): 2     db = pymysql.connect(host=db_host, user=db_user, password=db_password, port=db_port, db=db_name, charset=‘utf8‘) 3     cursor = db.cursor() 4     print(‘start inserting into db‘) 5     print(data) 6     t = datetime.now() 7     t = str(t).split(‘.‘)[0] 8     sql = "INSERT INTO fixed_asset_new (resource_id,resource_type,name,address,location,land_use,sell_type,land_type,is_bid,deal_status,source_url,province,city,district,plot_rate,declaration_time,start_time,expiration_time,start_price,transaction_price,min_raise_price,cash_deposit,trading_place,assignee,fixture_time,consult_tel,subject_type,housing_area,land_area,evaluate_price,auction_stage,memo,is_deleted,gmt_created,gmt_modified) VALUES (%d,%d,‘%s‘,‘%s‘,‘%s‘,%d,%d,%d,%d,%d,‘%s‘,‘%s‘,‘%s‘,‘%s‘,‘%s‘,‘%s‘,‘%s‘,‘%s‘,%d,%d,%d,%d,‘%s‘,‘%s‘,‘%s‘,‘%s‘,%d ,‘%s‘,‘%s‘,%d,%d,‘%s‘,%d,‘%s‘,‘%s‘)" % (data[‘resource_id‘],data[‘resource_type‘],data[‘name‘],data[‘address‘],data[‘location‘],data[‘land_use‘],data[‘sell_type‘],data[‘land_type‘],0,data[‘deal_status‘],data[‘source_url‘],data[‘province‘],data[‘city‘],data[‘district‘],data[‘plot_rate‘],data[‘declaration_time‘],data[‘start_time‘],data[‘expiration_time‘],data[‘start_price‘],data[‘transaction_price‘],data[‘min_raise_price‘],data[‘cash_deposit‘],data[‘trading_place‘],data[‘assignee‘],data[‘fixture_time‘],data[‘consult_tel‘],data[‘subject_type‘],data[‘housing_area‘],data[‘land_area‘],data[‘evaluate_price‘],data[‘auction_stage‘],data[‘memo‘],data[‘is_deleted‘],t,t) 9     try:10         cursor.execute(sql)11         db.commit()12         print(‘successful‘)13     except Exception as e:14         print(e)15         db.rollback()

也就是把2,3行代碼放在了函數外面,而write_into_db函數是放線上程主函數中的,如果放在函數外面,就會導致無法串連資料庫

MySQL資料庫報錯pymysql.err.InterfaceError: (0, '')

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.