Flask-DebugToolbar无法与mongoDB一起使用

时间:2018-08-06 04:39:22

标签: python-3.x flask mongoengine flask-mongoengine python-3.7

我想使用Flask-MongoEngine正常工作,但是我试图使调试工具栏正常工作,并且当我遵循文档时,得到如下所示的回溯。我能够正常运行烧瓶调试工具栏,但是由于我使用MongoDB作为数据库,因此我试图将烧瓶调试工具栏与MongoDB结合使用。我知道以下行是此回溯的原因。

app.config['DEBUG_TB_PANELS'] = ['flask_mongoengine.panels.MongoDebugPanel']

示例代码

from flask import Flask
from flask_debugtoolbar import DebugToolbarExtension

app = Flask(__name__)
app.config['DEBUG_TB_PANELS'] = ['flask_mongoengine.panels.MongoDebugPanel']
db = MongoEngine(app)
toolbar = DebugToolbarExtension(app)

引起回溯的行

app.config['DEBUG_TB_PANELS'] = ['flask_mongoengine.panels.MongoDebugPanel']


#traceback
Traceback (most recent call last):
  File "app.py", line 27, in <module>
    toolbar = DebugToolbarExtension(app)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask_debugtoolbar/__init__.py", line 58, in __init__
    self.init_app(app)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask_debugtoolbar/__init__.py", line 72, in init_app
    DebugToolbar.load_panels(app)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask_debugtoolbar/toolbar.py", line 50, in load_panels
    for panel_class in cls._iter_panels(app):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask_debugtoolbar/toolbar.py", line 57, in _iter_panels
    panel_class = cls._import_panel(app, panel_path)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask_debugtoolbar/toolbar.py", line 71, in _import_panel
    panel_class = import_string(path)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/werkzeug/utils.py", line 418, in import_string
    __import__(import_name)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask_mongoengine/panels.py", line 5, in <module>
    from flask_mongoengine import operation_tracker
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask_mongoengine/operation_tracker.py", line 26, in <module>
    '_unpack_response': pymongo.helpers._unpack_response,
AttributeError: module 'pymongo.helpers' has no attribute '_unpack_response'

1 个答案:

答案 0 :(得分:0)

自pymongo 3.6.0起,_unpack_respone方法似乎已消失或被重写。 一种解决方法是安装pymongo<3.6.0