Web user validate_email error in flask app

Hi, I have a flask app that uses web_user tryton module and i’m having an error with the validation_email method.

  File "<string>", line 12, in <Expression 'user.get_email_validation_url()'>
    
  File "/home/pedro/Documentos/Flexar/api-flexar/venv/lib/python3.8/site-packages/trytond/modules/web_user/user.py", line 293, in get_email_validation_url
    return _add_params(url, token=self.email_token)
  File "/home/pedro/Documentos/Flexar/api-flexar/venv/lib/python3.8/site-packages/trytond/modules/web_user/user.py", line 60, in _add_params
    return urllib.parse.urlunsplit(parts)
  File "/usr/lib/python3.8/urllib/parse.py", line 492, in urlunsplit
    _coerce_args(*components))
  File "/usr/lib/python3.8/urllib/parse.py", line 121, in _coerce_args
    raise TypeError("Cannot mix str and non-str arguments")
TypeError: Cannot mix str and non-str arguments

The code:

WebUser = tryton.pool.get('web.user')

login_parser = reqparse.RequestParser()
login_parser.add_argument('email', type=str)
login_parser.add_argument('password', type=str)

class Login(Resource):
    'Login'
    @tryton.transaction()
    def post(self):
        login_args = login_parser.parse_args()
        try:
            user, = WebUser.search([('email', '=', login_args['email'])])
        except Exception as e:
            return str(e), 400
        if not user.email_valid:
            WebUser.validate_email([user])

Tryton config:

[web]
listen=0.0.0.0:8000
hostname=localhost
reset_password_url=http://localhost:5000/
email_validation_url=http://localhost:5000/

[database]
uri=postgresql://tryton:tryton@127.0.0.1:5432
list=True
language=es

[session]
timeout=3600
web_timeout=7200
web_timeout_reset=86400

[email]
uri=smtp://localhost:25
from = <pedro@pedro-asus>

Any help will be appreciated. Thanks in advance!

No you are having a problem with get_email_validation_url().
But it is difficult to help without having the full traceback. But it seems you are calling the method with either an url that is not a string or when email_token has not yet been set.

Hi, thanks for your answer. Here is the full traceback:

Traceback (most recent call last):
  File "/home/pedro/Documentos/Flexar/api-flexar/quino/resources/login.py", line 35, in post
    WebUser.validate_email([user])
  File "/home/pedro/Documentos/Flexar/api-flexar/venv/lib/python3.8/site-packages/trytond-6.0.5-py3.8.egg/trytond/model/modelview.py", line 774, in wrapper
    return func(cls, records, *args, **kwargs)
  File "/home/pedro/Documentos/Flexar/api-flexar/venv/lib/python3.8/site-packages/trytond/modules/web_user/user.py", line 281, in validate_email
    _send_email(from_, users, cls.get_email_validation)
  File "/home/pedro/Documentos/Flexar/api-flexar/venv/lib/python3.8/site-packages/trytond/modules/web_user/user.py", line 46, in _send_email
    msg, title = email_func(user)
  File "/home/pedro/Documentos/Flexar/api-flexar/venv/lib/python3.8/site-packages/trytond/modules/web_user/user.py", line 287, in get_email_validation
    return get_email(
  File "/home/pedro/Documentos/Flexar/api-flexar/venv/lib/python3.8/site-packages/trytond-6.0.5-py3.8.egg/trytond/report/report.py", line 459, in get_email
    ext, content, _, title = Report_.execute(
  File "/home/pedro/Documentos/Flexar/api-flexar/venv/lib/python3.8/site-packages/trytond-6.0.5-py3.8.egg/trytond/report/report.py", line 193, in execute
    oext, content = cls._execute(
  File "/home/pedro/Documentos/Flexar/api-flexar/venv/lib/python3.8/site-packages/trytond-6.0.5-py3.8.egg/trytond/report/report.py", line 207, in _execute
    return cls.convert(action, cls.render(action, report_context))
  File "/home/pedro/Documentos/Flexar/api-flexar/venv/lib/python3.8/site-packages/trytond-6.0.5-py3.8.egg/trytond/report/report.py", line 303, in render
    data = template.generate(**report_context).render()
  File "/home/pedro/Documentos/Flexar/api-flexar/venv/lib/python3.8/site-packages/Genshi-0.7.5-py3.8.egg/genshi/core.py", line 183, in render
    return encode(generator, method=method, encoding=encoding, out=out)
  File "/home/pedro/Documentos/Flexar/api-flexar/venv/lib/python3.8/site-packages/Genshi-0.7.5-py3.8.egg/genshi/output.py", line 59, in encode
    return _encode(''.join(list(iterator)))
  File "/home/pedro/Documentos/Flexar/api-flexar/venv/lib/python3.8/site-packages/Genshi-0.7.5-py3.8.egg/genshi/output.py", line 243, in __call__
    for kind, data, pos in stream:
  File "/home/pedro/Documentos/Flexar/api-flexar/venv/lib/python3.8/site-packages/Genshi-0.7.5-py3.8.egg/genshi/output.py", line 674, in __call__
    for kind, data, pos in stream:
  File "/home/pedro/Documentos/Flexar/api-flexar/venv/lib/python3.8/site-packages/Genshi-0.7.5-py3.8.egg/genshi/output.py", line 779, in __call__
    for kind, data, pos in chain(stream, [(None, None, None)]):
  File "/home/pedro/Documentos/Flexar/api-flexar/venv/lib/python3.8/site-packages/Genshi-0.7.5-py3.8.egg/genshi/output.py", line 598, in __call__
    for ev in stream:
  File "/home/pedro/Documentos/Flexar/api-flexar/venv/lib/python3.8/site-packages/Genshi-0.7.5-py3.8.egg/genshi/core.py", line 291, in _ensure
    for event in stream:
  File "/home/pedro/Documentos/Flexar/api-flexar/venv/lib/python3.8/site-packages/Genshi-0.7.5-py3.8.egg/genshi/filters/i18n.py", line 688, in __call__
    for kind, data, pos in stream:
  File "/home/pedro/Documentos/Flexar/api-flexar/venv/lib/python3.8/site-packages/Genshi-0.7.5-py3.8.egg/genshi/template/base.py", line 641, in _include
    for event in stream:
  File "/home/pedro/Documentos/Flexar/api-flexar/venv/lib/python3.8/site-packages/Genshi-0.7.5-py3.8.egg/genshi/template/markup.py", line 326, in _match
    for event in stream:
  File "/home/pedro/Documentos/Flexar/api-flexar/venv/lib/python3.8/site-packages/Genshi-0.7.5-py3.8.egg/genshi/template/base.py", line 590, in _flatten
    values = [event[1]
  File "/home/pedro/Documentos/Flexar/api-flexar/venv/lib/python3.8/site-packages/Genshi-0.7.5-py3.8.egg/genshi/template/base.py", line 590, in <listcomp>
    values = [event[1]
  File "/home/pedro/Documentos/Flexar/api-flexar/venv/lib/python3.8/site-packages/Genshi-0.7.5-py3.8.egg/genshi/template/base.py", line 601, in _flatten
    result = _eval_expr(data, ctxt, vars)
  File "/home/pedro/Documentos/Flexar/api-flexar/venv/lib/python3.8/site-packages/Genshi-0.7.5-py3.8.egg/genshi/template/base.py", line 291, in _eval_expr
    retval = expr.evaluate(ctxt)
  File "/home/pedro/Documentos/Flexar/api-flexar/venv/lib/python3.8/site-packages/Genshi-0.7.5-py3.8.egg/genshi/template/eval.py", line 160, in evaluate
    return eval(self.code, _globals, {'__data__': data})
  File "<string>", line 12, in <Expression 'user.get_email_validation_url()'>
  File "/home/pedro/Documentos/Flexar/api-flexar/venv/lib/python3.8/site-packages/trytond/modules/web_user/user.py", line 293, in get_email_validation_url
    return _add_params(url, token=self.email_token)
  File "/home/pedro/Documentos/Flexar/api-flexar/venv/lib/python3.8/site-packages/trytond/modules/web_user/user.py", line 60, in _add_params
    return urllib.parse.urlunsplit(parts)
  File "/usr/lib/python3.8/urllib/parse.py", line 492, in urlunsplit
    _coerce_args(*components))
  File "/usr/lib/python3.8/urllib/parse.py", line 121, in _coerce_args
    raise TypeError("Cannot mix str and non-str arguments")
TypeError: Cannot mix str and non-str arguments

For me email_validation_url is not configured (probably your configuration file is not used).

Thanks, that was the problem. I have two config files and i was using the wrong one.