这是我将 Flask 应用程序升级到 0.10 版后继续遇到的错误:
AttributeError: 'Flask' object has no attribute 'json_encoder'
我意识到在发行说明中提到了对 JSON 序列化的许多升级,但没有说明它破坏了当前的实现。有谁知道解决这个问题?
更新:
这是完整的堆栈跟踪——
Traceback (most recent call last):
File "/Users/un/sites/env/visual_mg/lib/python2.7/site-packages/flask/app.py", line 1701, in __call__
return self.wsgi_app(environ, start_response)
File "/Users/un/sites/env/visual_mg/lib/python2.7/site-packages/flask/app.py", line 1689, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/Users/un/sites/env/visual_mg/lib/python2.7/site-packages/flask/app.py", line 1687, in wsgi_app
response = self.full_dispatch_request()
File "/Users/un/sites/env/visual_mg/lib/python2.7/site-packages/flask/app.py", line 1360, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Users/un/sites/env/visual_mg/lib/python2.7/site-packages/flask/app.py", line 1358, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/un/sites/env/visual_mg/lib/python2.7/site-packages/flask/app.py", line 1344, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Users/un/Sites/visual_mg/visual/attrs/views.py", line 165, in attrs_hs
return get_attrs(Attr, Attr_id, Attr_weight_tbl, Attr_weight_col, Attr_weight_mergeid, Attr_id_lens)
File "/Users/un/Sites/visual_mg/visual/attrs/views.py", line 129, in get_attrs
return jsonify(ret)
File "/Users/un/sites/env/visual_mg/lib/python2.7/site-packages/flask/helpers.py", line 198, in jsonify
indent=None if request.is_xhr else 2), mimetype='application/json')
File "/Users/un/sites/env/visual_mg/lib/python2.7/site-packages/flask/json.py", line 124, in dumps
_dump_arg_defaults(kwargs)
File "/Users/un/sites/env/visual_mg/lib/python2.7/site-packages/flask/json.py", line 97, in _dump_arg_defaults
kwargs.setdefault('cls', current_app.json_encoder)
File "/Users/un/sites/env/visual_mg/lib/python2.7/site-packages/werkzeug/local.py", line 336, in __getattr__
return getattr(self._get_current_object(), name)
AttributeError: 'Flask' object has no attribute 'json_encoder'
更新#2:
这是所有 python 库的副本——
Babel==0.9.6
Flask==0.10.1
Flask-Babel==0.8
Flask-Login==0.1.3
Flask-OAuth==0.12
Flask-SQLAlchemy==0.16
Flask-Script==0.5.3
Flask-WTF==0.8.3
Flask-WhooshAlchemy==0.55a
Jinja2==2.7
MarkupSafe==0.18
MySQL-python==1.2.3
SQLAlchemy==0.8.1
WTForms==1.0.4
Werkzeug==0.9.1
Whoosh==2.4.1
blinker==1.2
distribute==0.6.26
hiredis==0.1.1
httplib2==0.8
ipython==0.13.2
itsdangerous==0.21
matplotlib==1.2.1
numpy==1.7.1
oauth2==1.5.211
pandas==0.11.0
patsy==0.1.0
python-dateutil==2.1
pytz==2013b
readline==6.2.4.1
redis==2.7.6
scikits.statsmodels==0.3.1
scipy==0.12.0
six==1.3.0
speaklater==1.3
virtualenv==1.7.2
virtualenv-clone==0.2.4
virtualenvwrapper==3.5
wsgiref==0.1.2