Flask-SQLAlchemy(mysql.connector.errors.OperationalError)MySQL连接不可用

时间:2019-11-19 09:16:36

标签: python mysql python-3.x flask flask-sqlalchemy

首先,我有一个很长的JSON字符串,其中有很多IP和端口。

我要循环IP,然后转到数据库查询。此过程报告了异常。

相关代码如下:

            for result in nminfo['scan'].values():
                if result['status']['state'] == "up":
                    ip = result['addresses']['ipv4']
                    if ('osmatch' not in result) or len(result['osmatch']) == 0:
                        host_os = "unknow"
                    else:
                        host_os = result['osmatch'][0]['name']

                    # This query reported the exception
                    hosts_id = db.session.query(XXX.host_id).filter(XXX.host_ip == ip).first()
                    if host_id:
                        query_host_id = host_id[0]
                        XXX.query.filter_by(host_id=query_host_id).update({'host_os': host_os})
                        DDDD.query.filter_by(host_id=query_host_id,
                                                          task_stream_id=self.task_stream_id).update({'host_os': host_os})
                        db.session.commit()
                    else:
                        pass

我尝试了很多方法,例如更改SQLALCHEMY_POOL_RECYCLE的值,但这没用。

我想这与数据库连接池有关,但是仍然没有解决方案。

0 个答案:

没有答案