mailgun / mailgun/flanker

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

Open
#243 6 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.6k
Forks
213
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure with address.validate_address and inspect addresslib/address.py around line 322, then follow plugin_for_esp in addresslib/validate.py to understand the expected input type. Done means the reported custom-domain validation no longer raises the bytes/string TypeError and existing behavior remains intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.