WTForms: Install 'email_validator' for email validation support
Asked Answered
V

18

109

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()])
Viewfinder answered 22/4, 2020 at 3:31 Comment(4)
The stack trace could use some formatting.Unsheathe
error itself says Exception: Install 'email_validator' for email validation support. install email_validator.just install email_validator using pip install email-validator command. i had same problem just solved after installing email-validatorPremer
It is kind of dumb that we need another pip dependency for just email validation.Ruse
i install the validator, restarted vs code, still it's showing the same error.Grosso
O
118

If you take a look at wtforms/validators.py file in line 9:

import email_validator

Just install the package:

pip install email_validator
Olga answered 22/4, 2020 at 3:39 Comment(6)
Even the exception makes the solution clear: Exception: Install 'email_validator' for email validation support.Amadus
My bad ppl.. I was curious why it explicitly asked to do so on my local instance when it didn't on my vm. was trying to figure out how to anticipate and avoid such cross machine/platform errors from the beginning.Viewfinder
I encountered the same issue just today, where the app runs fine on my local but throws this error on the VM. WTForms released a new version 2.3.1 just today which broke things. Going back to 2.2.1 fixed it for me.Furniture
@Viewfinder Consider that install has a broad meaning so out of context it can mean a lot more than just to run pip install.Percolator
I had the same issue with WTForms 2.3.3. 'pip install email-validator' solved it. email-validator version: 1.1.3. Although it installed a few other packages: idna and dnspython.Churr
To avoid issues in VMs, make sure to include email_validator in your requirements.txt file.Expectation
I
27

If you want it installed with wtforms:

pip install wtforms[email]
Idaho answered 24/4, 2020 at 3:30 Comment(2)
I got the message: no matches found: wtforms[email]Agley
@MichaelLossagk I tried this just now (Python 3.7.9) and it still works. Moreover, the option for email is still in their config: github.com/wtforms/wtforms/blob/master/setup.cfgIdaho
V
24

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).

Valadez answered 29/11, 2020 at 1:43 Comment(0)
T
8

Try install

pip install email-validator
Tiffie answered 17/5, 2020 at 9:15 Comment(0)
S
5

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.

Santinasantini answered 23/4, 2020 at 0:53 Comment(1)
this version did the trick for me using google colab notebooks and python 3.10Lepsy
R
5

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.

Robey answered 18/6, 2020 at 12:53 Comment(0)
X
3

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

Xiphisternum answered 3/10, 2020 at 16:23 Comment(0)
B
3

This should work as it worked for me. Just install this in project terminal:

pip install email-validator

Balf answered 26/3, 2021 at 23:45 Comment(0)
P
3

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:(

Pandurate answered 23/12, 2021 at 5:31 Comment(0)
U
2

Try install

pip install WTForms==2.1 
Uprise answered 25/6, 2020 at 16:39 Comment(2)
Hello! While this code may solve the question, including an explanation of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please edit your answer to add explanations and give an indication of what limitations and assumptions apply.Honig
This also did not solve the issue, as I've that version of WTForms, and I get the same exception.Obvert
A
2

Adding to what is already said for future referance,

pip install email_validator

P.S You dont need to import email_validator after installing.

Aetna answered 14/10, 2021 at 19:30 Comment(0)
F
1

In your project directory run:

pip install email_validator

This worked for me!

Fleabag answered 12/3, 2021 at 22:7 Comment(0)
E
1

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
Ens answered 9/8, 2021 at 15:13 Comment(0)
A
1

Installing the dependency email_validator as following solved the issue:

pip3 install email_validator
Abroach answered 20/3, 2023 at 10:28 Comment(0)
A
0

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]"
Angry answered 13/5, 2021 at 14:20 Comment(0)
D
0

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

Dedicated answered 22/8, 2021 at 11:28 Comment(1)
This has already been mentioned in the other answers.Volsung
M
0

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.

Mcatee answered 1/12, 2021 at 5:53 Comment(0)
W
0

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
Walkling answered 5/5 at 12:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.