How to configure CORS


I was trying trytond 5.2 with gunicorn and works well with tryton but not with sao. I worked before with uwsgi and works without the need to has CORS configured, but with gunicorn doesn’t work.

I was reading about Configuration file for Tryton — trytond 5.5 documentation but I don’t know how to configure it correctly? Is apart from the docs, where can find an example of that?

Thanks in advance.

Could you explain your setup and why you think you need CORS?

The configuration of CORS should not be needed for sao as long as it is distributed from the same hostname as trytond (indeed sao should not work otherwise with or without CORS).
The configuration for CORS should look like:

cors =

The setup with uwsgi under emperor.uwsgi.service is:

virtualenv = /opt/test
env = TRYTOND_CONFIG=/opt/test/tr.conf
workers = %k
threads = 1
touch-chain-reload = %dreload

The setup with gunicorn under systemd is:

Description=test gunicorn daemon

ExecStartPre=/bin/bash -c 'mkdir -p /run/test_gunicorn; chown www-data:www-data /run/test_gunicorn$
ExecStart=/opt/test/bin/python /opt/test/bin/gunicorn --pid /run/test_gunicorn/pid   \
          --bind unix:/run/test_gunicorn/socket trytond.application:app \
          --user=www-data --group=www-data --pythonpath=/opt/test/bin/ \
          --name=test_gunicorn --log-file=/var/log/gunicorn/test.gunicorn.log \
          --timeout=3600 --threads=1 \
          --workers=9 --error-logfile=/var/log/gunicorn/test.gunicorn.error \
          --log-level debug


The config with uwsgi works on tryton 5.0, 5.2 and 5.4 and sao 5.0, 5.2, 5.4 using nginx as proxy server.

Using nginx as proxy server the given config with gunicorn works with tryton 5.0, 5.2, 5.4 and sao 5.0. With sao 5.2 and 5.4 gives the follow traceback:

File "/opt/test/lib/python3.7/site-packages/trytond/", line 181, in __call__
    return self.wsgi_app(environ, start_response)
  File "/opt/test/lib/python3.7/site-packages/trytond/", line 187, in __call__
    return, start_response)
  File "/opt/test/lib/python3.7/site-packages/trytond/", line 159, in wsgi_app
  File "/opt/test/lib/python3.7/site-packages/werkzeug/", line 772, in abort
    return _aborter(status, *args, **kwargs)
  File "/opt/test/lib/python3.7/site-packages/werkzeug/", line 753, in __call__
    raise self.mapping[code](*args, **kwargs)
werkzeug.exceptions.Forbidden: 403 Forbidden: You don't have the permission to access the requested resource. It is either read-protected or not readable by the server.

I configured cors similar to these but doesn’t work neither.

I guess you should inspect the Origin and Host headers of the request received by Tryton.

By the way, I forgot that CORS should contain the schema so it should be like that:

cors =

It works after configure it according to.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.