Skip to content

TypeError: cannot use a string pattern on a bytes-like object #243

@AjayKumar2916

Description

@AjayKumar2916

Python version 3.7.7
flanker version 0.9.11

from flanker.addresslib import address                                                                                                                                                                                           

address.validate_address(<custom domaian email address>)  
----> 1 address.validate_address('custom domaian email address')

~/.virtualenvs/newvenv/lib/python3.7/site-packages/flanker/utils.py in wrapper(*args, **kwargs)
     62         @wraps(f)
     63         def wrapper(*args, **kwargs):
---> 64             return_value = f(*args, **kwargs)
     65             if 'metrics' in kwargs and kwargs['metrics'] == True:
     66                 #return all values

~/.virtualenvs/newvenv/lib/python3.7/site-packages/flanker/addresslib/address.py in validate_address(addr_spec, metrics, skip_remote_checks)
    321     # lookup custom local-part grammar if it exists
    322     bstart = time()
--> 323     plugin = plugin_for_esp(exchanger)
    324     mtimes['custom_grammar'] = time() - bstart
    325     if plugin and plugin.validate(paddr) is False:

~/.virtualenvs/newvenv/lib/python3.7/site-packages/flanker/addresslib/validate.py in plugin_for_esp(mail_exchanger)
    127     """
    128     for grammar in _CUSTOM_GRAMMAR_LIST:
--> 129         if grammar[0].match(mail_exchanger):
    130             return grammar[1]
    131 

TypeError: cannot use a string pattern on a bytes-like object

I found the fix
flanker/flanker/addresslib/address.py line 322

from
plugin = plugin_for_esp(exchanger)

to
plugin = plugin_for_esp(exchanger.decode('utf-8'))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions