flanker icon indicating copy to clipboard operation
flanker copied to clipboard

TypeError during email validation

Open mithunmanohar opened this issue 6 years ago • 5 comments

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

address.validate_address('[email protected]')

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 ?

mithunmanohar avatar Nov 27 '18 09:11 mithunmanohar

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

amk5 avatar Dec 15 '18 20:12 amk5

+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('[email protected]'))
...
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()

robbymurphy avatar Jan 02 '19 17:01 robbymurphy

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

jrborbars avatar Jun 11 '19 21:06 jrborbars

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

dineshrav avatar Oct 18 '19 19:10 dineshrav

Updating to 0.9.11 fix this issue for me.

chingc avatar Jun 19 '20 15:06 chingc