Reputation: 1189
Getting exception when running the following code for form validation.
File "/Users/homeduvvuri/Documents/Learning/PartyGoUdemy/PartGo/user/forms.py", line 11, in BaseUserForm
email = EmailField('Email', [validators.DataRequired(), validators.Email()])
File "/Users/homeduvvuri/Documents/Learning/PartyGoUdemy/PartGo/partgo-env/lib/python3.7/site-packages/wtforms/validators.py", line 332, in __init__
raise Exception("Install 'email_validator' for email validation support.")
Exception: Install 'email_validator' for email validation support.
Runs perfectly on codeanywhere VM. Does not on local machine.
from flask_wtf import FlaskForm
from flask_wtf.file import FileField, FileAllowed
from wtforms import Form, StringField, PasswordField, validators, ValidationError
from wtforms.validators import InputRequired, Email
from wtforms.fields.html5 import EmailField
from wtforms.widgets import TextArea
from user.models import User
class BaseUserForm(FlaskForm):
name = StringField('Name', [validators.DataRequired(), validators.Length(min=2, max=30)])
email = EmailField('Email', [validators.DataRequired(), validators.Email()])
Upvotes: 109
Views: 116524
Reputation: 187
If you are using Ubuntu python packages, then this works nicely ..
sudo apt install python3-email-validator
Upvotes: 0
Reputation: 1
I don't know the exact issue but it will work if you add these in requirements.txt:
Flask_WTF==1.2.1
WTForms==3.0.1
Upvotes: 0
Reputation: 65
Installing the dependency email_validator
as following solved the issue:
pip3 install email_validator
Upvotes: 1
Reputation:
Inside wtforms/validators.py
file, line 392, you can see that there is exception handling for this occurrence in particular, which is why the following lines are executed to throw the alert
if email_validator is None: # pragma: no cover
raise Exception("Install 'email_validator' for email validation
support.")
Solution is to pip install email-validator
in the same location/directory for wtforms/validators.py sake.
I had the same error before:(
Upvotes: 3
Reputation: 163
If you have removed build dependencies before running your app, please check whether idna
exists.
For Alpine Linux, use apk add py3-idna
before installing build dependencies. Then this package will not be in the build dependency virtual package so will not be removed automatically.
Upvotes: 0
Reputation: 300
Adding to what is already said for future referance,
pip install email_validator
P.S You dont need to import email_validator after installing.
Upvotes: 2
Reputation: 9
If we use wtforms.validators.Email in our python program, then it raise an exception that asks us to install the email_validator for email validation support. The solution for that problem is to type the following command in terminal pip install email_validator
Upvotes: 0
Reputation: 25
from wtf forms
Validates an email address. Requires email_validator package to be installed. For ex: pip install wtforms[email].
pip install wtforms[email]
pip install email_validator
Upvotes: 1
Reputation: 33
I don't know if the root cause was that I used zsh in Terminal but I also get the error "zsh: no matches found: wtforms[email]" when I tried the command below.
pip install wtforms[email]
However, I tried to do the following command, it worked for me.
pip install -U "wtforms[email]"
Upvotes: 0
Reputation: 439
This should work as it worked for me. Just install this in project terminal:
pip install email-validator
Upvotes: 3
Reputation: 69
In your project directory run:
pip install email_validator
This worked for me!
Upvotes: 1
Reputation: 12772
From WTForms 2.3.0 version, the email validation is handled by an external library called email-validator
(PR #429). If you want to enable email validation support, you either need to install WTForms with extra requires email
:
$ pip install wtforms[email]
Or you can install email-validator
directly:
$ pip install email-validator
Or you can back to the old version of WTForms:
$ pip install wtforms==2.2.1
P.S. If you are using Flask-WTF, except for install email-validator
directly, you can also use email
extra (if PR #423 got merged) in the next release (> 0.14.3).
Upvotes: 24
Reputation: 81
you need pip install email-validator
, wtforms depend on email-validator.
you can see email-validator module on Github https://github.com/JoshData/python-email-validator
Upvotes: 3
Reputation: 123
This happened to me as well when i run it using virtual env. anaconda 3.7 However when i switched my project interpreter back to my local machine Python 3.7, then i run:
pip install email_validator
it worked fine.
I just found it strange that I couldn't install the module "email_validator" in my anaconda Project Interpreter. So i suggest that you try with local machine first.
Upvotes: 5
Reputation: 151
I had the same problem with the latest updates, tried to install email_validator and flask-validator and continued with this exception. Solved by adding in requirements.txt the following line: email-validator == 1.0.5 as suggested [here].(https://github.com/alphagov/notifications-admin/commit/5ce2906c5aa6d16)
Actually wtforms[email]==2.3.1 is what I need.
Upvotes: 6
Reputation: 1511
If you take a look at wtforms/validators.py file in line 9:
import email_validator
Just install the package:
pip install email_validator
Upvotes: 123