我有一个烧瓶应用程序,我很难让它运行。在逐步修复错误之后,我现在在 session.commit 之后被ConnectionRefusedError卡住了。如果我删除此行,则应用程序运行良好。即使删除了这一行,我也可以看到数据正在被插入到数据库中。所以我的意思是这条线的目的是什么,我该如何解决这个错误。这是 misc.py 中的代码
@flask_app.after_request
def commit(response):
session = current_app.db.session
if response.status_code < 400:
try:
session.commit()
except Exception as e:
l.exception("database commit failed")
return InternalError(str(e)).get_response(request.environ)
else:
session.rollback()
return response
这是完整的 Traceback
Traceback (most recent call last):
File "E:\Projects\PythonProjects\myappnam\app\views\misc.py", line 53, in commit
session.commit()
File "C:\Program Files\Python38\lib\site-packages\sqlalchemy\orm\scoping.py", line 162, in do
return getattr(self.registry(), name)(*args, **kwargs)
File "C:\Program Files\Python38\lib\site-packages\sqlalchemy\orm\session.py", line 1036, in commit
self.transaction.commit()
File "C:\Program Files\Python38\lib\site-packages\sqlalchemy\orm\session.py", line 510, in commit
self.session.dispatch.after_commit(self.session)
File "C:\Program Files\Python38\lib\site-packages\sqlalchemy\event\attr.py", line 322, in __call__
fn(*args, **kw)
File "C:\Program Files\Python38\lib\site-packages\flask_sqlalchemy\__init__.py", line 224, in after_commit
models_committed.send(session.app, changes=list(d.values()))
File "C:\Program Files\Python38\lib\site-packages\blinker\base.py", line 266, in send
return [(receiver, receiver(sender, **kwargs))
File "C:\Program Files\Python38\lib\site-packages\blinker\base.py", line 266, in <listcomp>
return [(receiver, receiver(sender, **kwargs))
File "E:\Projects\PythonProjects\myappnam\app\views\misc.py", line 72, in on_models_committed
callback()
File "E:\Projects\PythonProjects\myappnam\app\views\users.py", line 314, in <lambda>
after_commit(lambda: invalidate("users"))
File "E:\Projects\PythonProjects\myappnam\app\controllers\caching.py", line 136, in invalidate
data_cache.incr(dependency, 1)
File "C:\Program Files\Python38\lib\site-packages\pymemcache\client\base.py", line 609, in incr
results = self._misc_cmd([cmd], b'incr', noreply)
File "C:\Program Files\Python38\lib\site-packages\pymemcache\client\base.py", line 911, in _misc_cmd
self._connect()
File "C:\Program Files\Python38\lib\site-packages\pymemcache\client\base.py", line 285, in _connect
sock.connect(self.server)
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it
127.0.0.1 - - [29/Dec/2019 15:32:37] "POST /api/v1/users/sign_up HTTP/1.1" 400 -
[29/12/2019 15:32:37.339|15068| INFO|werkzeug |_internal.py:122 _log ]: 127.0.0.1 - - [29/Dec/2019 15:32:37] "POST /api/v1/users/sign_up HTTP/1.1" 400 -