python
data_error
ai_generated
true
pydantic.errors.EmailError: value is not a valid email address
ID: python/pydantic-email-format-invalid
80%Fix Rate
87%Confidence
0Evidence
2024-03-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 2.x | active | — | — | — |
Root Cause
Using EmailStr type, the input string does not conform to email format (e.g., missing @, invalid domain).
generic中文
使用 EmailStr 类型时,输入字符串不符合电子邮件格式(例如缺少 @、域名无效)。
Workarounds
-
95% success
Use EmailStr from pydantic: email: EmailStr
-
90% success
Sanitize input before validation: @field_validator('email', mode='before') def clean(cls, v): return v.strip()
Dead Ends
Common approaches that don't work:
-
60% fail
Custom regex may not capture all email edge cases, leading to false positives.
-
70% fail
Empty string is not a valid email, even if optional.