flask-wtf icon indicating copy to clipboard operation
flask-wtf copied to clipboard

AttributeError: module 'quart.json' has no attribute 'JSONEncoder'

Open khteh opened this issue 2 years ago • 2 comments

Bump into this error when I run pipenv run hypercorn --reload --quic-bind 0.0.0.0:4433 --certfile server.crt --keyfile server.key --bind 0.0.0.0:8080 src.main:app:

<snip>
  File "/usr/src/PythonRestAPI/src/main.py", line 5, in <module>
    from flask_wtf.csrf import CSRFProtect, CSRFError
  File "/home/khteh/.local/share/virtualenvs/PythonRestAPI-JI5RzKtM/lib/python3.10/site-packages/flask_wtf/__init__.py", line 4, in <module>
    from .recaptcha import Recaptcha
  File "/home/khteh/.local/share/virtualenvs/PythonRestAPI-JI5RzKtM/lib/python3.10/site-packages/flask_wtf/recaptcha/__init__.py", line 1, in <module>
    from .fields import RecaptchaField
  File "/home/khteh/.local/share/virtualenvs/PythonRestAPI-JI5RzKtM/lib/python3.10/site-packages/flask_wtf/recaptcha/fields.py", line 3, in <module>
    from . import widgets
  File "/home/khteh/.local/share/virtualenvs/PythonRestAPI-JI5RzKtM/lib/python3.10/site-packages/flask_wtf/recaptcha/widgets.py", line 6, in <module>
    JSONEncoder = json.JSONEncoder
AttributeError: module 'quart.json' has no attribute 'JSONEncoder'

Environment:

  • Python version: 3.10.4
  • Flask-WTF version: 1.0.1
  • Flask version: 2.1.3 https://github.com/pallets/quart/issues/163

khteh avatar Jul 26 '22 04:07 khteh

A temporary issue that seems to work for me is to change the import to:

from flask.json.provider import DefaultJSONProvider

and then change the JSONEncoder object to:

JSONEncoder = DefaultJSONProvider

guillermohs9 avatar Oct 08 '22 13:10 guillermohs9

How to use this in our applicaton? The error happens inside the library and my application doesn't reference JSONEncoder directly.

khteh avatar Oct 17 '22 03:10 khteh