Redis returns byte-like object instead of string so flanker crashes
hoppla20 opened this issue · 1 comments
hoppla20 commented
After installing redis flanker crashes when I try to validate an address for the second time with following error logs:
Traceback (most recent call last):
File "/data/workspace/campusjaeger/mailgun-microservice/env/lib/python3.6/site-packages/flask/app.py", line 2464, in __call__
return self.wsgi_app(environ, start_response)
File "/data/workspace/campusjaeger/mailgun-microservice/env/lib/python3.6/site-packages/flask/app.py", line 2450, in wsgi_app
response = self.handle_exception(e)
File "/data/workspace/campusjaeger/mailgun-microservice/env/lib/python3.6/site-packages/flask/app.py", line 1867, in handle_exception
reraise(exc_type, exc_value, tb)
File "/data/workspace/campusjaeger/mailgun-microservice/env/lib/python3.6/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/data/workspace/campusjaeger/mailgun-microservice/env/lib/python3.6/site-packages/flask/app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "/data/workspace/campusjaeger/mailgun-microservice/env/lib/python3.6/site-packages/flask/app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/data/workspace/campusjaeger/mailgun-microservice/env/lib/python3.6/site-packages/flask/app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/data/workspace/campusjaeger/mailgun-microservice/env/lib/python3.6/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/data/workspace/campusjaeger/mailgun-microservice/env/lib/python3.6/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/data/workspace/campusjaeger/mailgun-microservice/env/lib/python3.6/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/data/workspace/campusjaeger/mailgun-microservice/emailValidation.py", line 27, in checkMail
parsedAddress = address.validate_address(addressValue)
File "/data/workspace/campusjaeger/mailgun-microservice/env/lib/python3.6/site-packages/flanker/utils.py", line 64, in wrapper
return_value = f(*args, **kwargs)
File "/data/workspace/campusjaeger/mailgun-microservice/env/lib/python3.6/site-packages/flanker/addresslib/address.py", line 322, in validate_address
plugin = plugin_for_esp(exchanger)
File "/data/workspace/campusjaeger/mailgun-microservice/env/lib/python3.6/site-packages/flanker/addresslib/validate.py", line 129, in plugin_for_esp
if grammar[0].match(mail_exchanger):
TypeError: cannot use a string pattern on a bytes-like object
After tracing the error I found out, that the lookup_exchanger_in_cache
method in validate.py
returns a byte instead of a string.
I fixed the issue by adding decode_response=True
in the redis_driver.py
in line 18:
# replaced
self.r = redis.StrictRedis(host=host, port=port, db=db)
# with
self.r = redis.StrictRedis(host=host, port=port, db=db, decode_responses=True)
But I don't want to change files in the plugin so I wanted to ask whether anybody else experienced this error.