今天入库的时候出现了报错pymysql.err.InterfaceError: (0, ''),经过排查,发现是由于把连接数据库的代码放到了插入函数的外部,导致多线程运行出错

 def write_into_db(data):
db = pymysql.connect(host=db_host, user=db_user, password=db_password, port=db_port, db=db_name, charset='utf8')
cursor = db.cursor()
print('start inserting into db')
print(data)
t = datetime.now()
t = str(t).split('.')[0]
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)
try:
cursor.execute(sql)
db.commit()
print('successful')
except Exception as e:
print(e)
db.rollback()

也就是把2,3行代码放在了函数外面,而write_into_db函数是放在线程主函数中的,如果放在函数外面,就会导致无法连接数据库

MySQL数据库报错pymysql.err.InterfaceError: (0, '')的更多相关文章

  1. pycharm pymysql连接mysql 报错 pymysql.err.InterfaceError: (0, '')

    pycharm  pymysql连接mysql  执行MySQL操作遇到以下报错信息: conn.query(q) File "C:\Software\Python37\lib\site-p ...

  2. 【Python+Django+Pytest】数据库异常pymysql.err.InterfaceError: (0, '') 解决方案

    问题背景: 接口自动化测试平台,在执行测试案例之外,还需要做以下五件事情(或步骤): 1.查询用户在数据准备中预置的测试套件层数据初始化相关sql  (setUp_class方法中) 2.查询用户在数 ...

  3. pymysql.err.InterfaceError: (0, '')解决办法

    导致这个错误的原因是通过pymysql连接MySQL,没有关闭连接的操作,所以短时间内不会出问题,长时间保持这个连接会出现连接混乱.虽然看着自己的代码没错,还是会报 pymysql.err.Inter ...

  4. 连接mysql数据库报错java.sql.SQLException: The server time zone value '�й���׼ʱ��' is unrecognized...解决方法

    今天连接mysql数据库报错如下: java.sql.SQLException: The server time zone value '�й���׼ʱ��' is unrecognized or r ...

  5. 报错pymysql.err.DataError: (1406, "Data too long for column 'gender' at row 1")

    在Django默认的admin后台创建超级用户时, 报错pymysql.err.DataError: (1406, "Data too long for column 'gender' at ...

  6. Mysql数据库报错1264

    数据库报错 [Err] 1264 - Out of range value adjusted for column 'ID' at row 1 修改MYSQL下的my.ini, 将 sql-mode= ...

  7. Node.js连接MySQL数据库报错

    解决Node.js第一次连接MySQL数据库时出现[SELECT ERROR] - ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authen ...

  8. 关于springboot 连接mysql 数据库报错问题

    springboot连接MySQL运行报错: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more ...

  9. MySQL数据库报错 > 1366 - Incorrect string value: ‘\xE6\xB1\x9F\xE6\x96\x87‘ for column ‘Teacher‘ at row 1

    数据库报错这个多半是数据库在创建的时候没有选择字符编码,导致输入中文的时候出现报错. > 1366 - Incorrect string value: '\xE6\xB1\x9F\xE6\x96 ...

随机推荐

  1. Android 获取Activity当前view

    View cv = getWindow().getDecorView(); 来自为知笔记(Wiz)

  2. python接口自动化测试(八)-unittest-生成测试报告

    用例的管理问题解决了后,接下来要考虑的就是报告我问题了,这里生成测试报告主要用到 HTMLTestRunner.py 这个模块,下面简单介绍一下如何使用: 一.下载HTMLTestRunner下载: ...

  3. EAS开发之挂菜单

        一:以管理员账号登录   二:挂菜单     点击菜单栏"系统"——客户化菜单编辑——选中上级目录——点击 新建——命名.键入唯一编码,把ui.java类的全路径,拷贝到 ...

  4. Unable to find vcvarsall.bat

    windows下pip安装各种包时,经常会遇到此错误.本文介绍解决方案. 第一步:安装visual studio 第二步:安装everything 打开everything,搜索vcvarsall.b ...

  5. 【C++】C++中的函数

    目录结构: contents structure [-] 简介 可变形参的函数 initializer_list形参 省略符形参 main函数处理命令行选项 函数指针与函数引用 inline内联函数 ...

  6. npm 发布包和删除包(2019最新攻略)

  7. Tomcat热部署的三种方式

    原文地址:https://blog.csdn.net/nlwangxin/article/details/49734659热部署是指在你修改项目BUG的时候对JSP或JAVA类进行了修改在不重启WEB ...

  8. .NET CORE控制器里的方法取传参的坑

    把以前的ASP.NET MVC的项目改成用.NET CORE来写,写好了部署上去了,结果问题一大堆,今天慢慢检查了一下,发现一个大坑: 写控制器里的方法接收参数数都是直接写在控制器的方法参数里的,如: ...

  9. SQL Server 2016新特性:列存储索引新特性

    SQL Server 2016新特性:列存储索引新特性 行存储表可以有一个可更新的列存储索引,之前非聚集的列存储索引是只读的. 非聚集的列存储索引支持筛选条件. 在内存优化表中可以有一个列存储索引,可 ...

  10. Asp.Net WebApi上传图片

    webapi using System; using System.Collections; using System.Collections.Generic; using System.Diagno ...