mailgun / flanker

Python email address and Mime parsing library
http://www.mailgun.com
Apache License 2.0
1.63k stars 204 forks source link

TypeError during email validation #218

Open mithunmanohar opened 5 years ago

mithunmanohar commented 5 years ago

When I am trying to validate a email, getting the below error both in python 2 and 3.

address.validate_address('mithun.manohar@xxxx.com')

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\xxx\AppData\Local\Programs\Python\Python37-32\lib\site-packages\flanker\utils.py", line 64, in wrapper
return_value = f(*args, **kwargs)
File "C:\Users\xxx\AppData\Local\Programs\Python\Python37-32\lib\site-packages\flanker\addresslib\address.py", line 312, in validate_address
exchanger, mx_metrics = mail_exchanger_lookup(paddr.hostname, metrics=True)
File "C:\Users\xxx\AppData\Local\Programs\Python\Python37-32\lib\site-packages\flanker\utils.py", line 64, in wrapper
return_value = f(*args, **kwargs)
File "C:\Users\xxx\AppData\Local\Programs\Python\Python37-32\lib\site-packages\flanker\addresslib\validate.py", line 156, in mail_exchanger_lookup
mx_hosts = lookup_domain(domain)
File "C:\Users\xxx\AppData\Local\Programs\Python\Python37-32\lib\site-packages\flanker\addresslib\validate.py", line 210, in lookup_domain
if len(mx_hosts) == 0:
TypeError: object of type 'filter' has no len()

Anyone faced similar issue ?

amk5 commented 5 years ago

Try adding:

from functools import reduce

def ilen(iterable):
    return reduce(lambda sum, element: sum + 1, iterable, 0)

Then change the lookup_domain method in validate.py:

len_mx_hosts = ilen(_get_dns_lookup()[fqdn])
 if len_mx_hosts == 0:
  return None
robbymurphy commented 5 years ago

+1

Getting the same issue when trying to validate. The validate_address method seems like a pretty essential api method and it is completely broken.

from flanker.addresslib import address

print(address.validate_address('robbymurphy@gmail.com'))
...
File "/Users/rmurphy/.pyenv/versions/3.6.0/lib/python3.6/site-packages/flanker/addresslib/validate.py", line 210, in lookup_domain
    if len(mx_hosts) == 0:
TypeError: object of type 'filter' has no len()
jrborbars commented 5 years ago

+1 Python (CPython 3.7.3), Flask 1.0.2, same line as above (@robbymurphy ). TypeError: object of type 'filter' has no len()

if len(mx_hosts) == 0:
dineshrav commented 4 years ago

I am having the exact same issue... Can anyone help.... I tried the option suggested by @amk5.. still no luck

chingc commented 4 years ago

Updating to 0.9.11 fix this issue for me.