Proteus connecting to postgres

Hello,

I am using Docker compose and there is nothing in the Tryton database. I am trying to connect proteus to a running Trython to set it up.

$ sudo docker-compose up -d

(Running in Docker, I am not sure where the configuration file path is that I can pass into config.set_trytond.)

$ `pip install proteus`

`>>> from proteus import config `
`>>> config.set_trytond('tryton-postgres') `

But I get the error

ModuleNotFoundError: No module named 'trytond.backend.'

Full error trace and yml file below.

Hope you can help.

Kind regards,

Douglas

Here is my docker-compose.yml

version: "3.5"

services:
    tryton:
        image: tryton/tryton:5.4
        restart: always
        environment:
          - DB_HOSTNAME=tryton-postgres
          - DB_PASSWORD=${POSTGRES_PASSWORD}
          - TRYTOND_WEB__NUM_PROXIES=1
        volumes:
          - tryton-data:/var/lib/trytond/db
          - tryton-www-static-data:/var/lib/trytond/www
        expose:
          - "8000"
        depends_on:
          - tryton-postgres

    tryton-postgres:
        image: postgres:12
        restart: always
        environment:
          - PGDATA=/var/lib/postgresql/data/pgdata
          - POSTGRES_DB=tryton
          - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
        volumes:
          - tryton-postgres-data:/var/lib/postgresql/data
        expose:
          - "5432"

    nginx:
        image: nginx:1.17
        restart: always
        environment:
          - TZ=Europe/London
        volumes:
          - ./nginx-config:/etc/nginx/conf.d:ro
          - tryton-www-static-data:/var/www/static/tryton:ro
        ports:
          - "80:80"
          - "443:443"
        depends_on:
          - tryton

volumes:
    tryton-data:
        external: True

    tryton-postgres-data:
        external: True

    tryton-www-static-data:

Here is the full error

ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-10-33ed1c5263cc> in <module>
----> 1 config.set_trytond('tryton-postgres')

~/miniconda3/lib/python3.7/site-packages/proteus/config.py in set_trytond(database, user, config_file)
    291         config_file=None):
    292     'Set trytond package as backend'
--> 293     _CONFIG.current = TrytondConfig(database, user, config_file=config_file)
    294     return _CONFIG.current
    295 

~/miniconda3/lib/python3.7/site-packages/proteus/config.py in __init__(self, database, user, config_file)
    229         from trytond.config import config
    230         config.update_etc(config_file)
--> 231         from trytond.pool import Pool
    232         from trytond.transaction import Transaction
    233         self.database = database

~/miniconda3/lib/python3.7/site-packages/trytond/pool.py in <module>
      4 from threading import RLock
      5 import logging
----> 6 from trytond.modules import load_modules, register_classes
      7 from trytond.transaction import Transaction
      8 import builtins

~/miniconda3/lib/python3.7/site-packages/trytond/modules/__init__.py in <module>
     15 
     16 import trytond.tools as tools
---> 17 from trytond.cache import Cache
     18 from trytond.config import config
     19 from trytond.exceptions import MissingDependenciesException

~/miniconda3/lib/python3.7/site-packages/trytond/cache.py in <module>
     14 from sql.functions import CurrentTimestamp, Function
     15 
---> 16 from trytond import backend
     17 from trytond.config import config
     18 from trytond.transaction import Transaction

~/miniconda3/lib/python3.7/site-packages/trytond/backend/__init__.py in <module>
     19 _modname = 'trytond.backend.%s' % name
     20 try:
---> 21     _module = importlib.import_module(_modname)
     22 except ImportError:
     23     if not pkg_resources:

~/miniconda3/lib/python3.7/importlib/__init__.py in import_module(name, package)
    125                 break
    126             level += 1
--> 127     return _bootstrap._gcd_import(name[level:], package, level)
    128 
    129 

ModuleNotFoundError: No module named 'trytond.backend.'

Please show how you are executing the proteus script?
I guess you are not using the entrypoint.

Hello,

I am unaware of what an ‘entrypoint’ is so will no doubt be doing this wrong. I am not using a script, just experimenting interactively…

$ ipython
In [1]: from proteus import config                                              
In [2]: config.set_trytond('tryton-postgres')       

Thanks,

Douglas

See https://docs.docker.com/engine/reference/builder/#entrypoint

So how are you launching this script in docker.

Hi Douglas,

Just incase your were not aware, and to help clarify, there are two set_... methods in proteus.config:

  • set_trytond: Used to connect to a local trytond server.
  • set_xmlrpc: Used to connect to a remote trytond server.

So, to use the set_trytond method you need to be running the script inside the docker container (with the environment setup correctly, which is done by the entrypoint.sh script), so you will need to do something like this:

$ sudo docker-compose exec tryton /entrypoint.sh python3

You can then run your script (you need to replace <database_name> with the name of your database, which will be tryton based on your docker-compose.yaml file):

from proteus import config
from os import getenv
config.set_trytond(getenv('TRYTOND_DATABASE_URI') + '<database_name>')

In version 5.8+ this change means in the future you will be able to do just this instead:

from proteus import config
config.set_trytond('<database_name>')

Alternatively you can use the set_xmlrpc method to connect to your Tryton server from outside your container by doing something like this:

$ pip install proteus
$ python3

Then use set_xmlrpc to connect to your server (replacing the parts in <> as appropriate, you may need to quote / encode any special characters in your password):

from proteus import config
config.set_xmlrpc('https://<username>:<password>@<server>:<port>/<database_name>/')
1 Like

Hi,

I think that I am making progress but don’t know what to do next.

I can access bash in the the running Tryton container, start Python, import proteus config

$ sudo docker exec -it tryton-deployment_tryton_1 bash
trytond@4b8542948804:/$ python3
>>> from proteus import config
>>> config.set_trytond()

I don’t know how to connect to the database. I think I need to find a config file for set_trytond with the correct details.

Any advice?

Thanks,

Douglas

If the config.set_trytond() was successful, then you are connected to the database.

Next you can activate modules, get data, change data, and do pretty much all the stuff you can do in the desktop or web clients: Tryton Scripting Client — tryton-proteus latest documentation

It worked from inside the container. Have not tried the external method yet.

Thank you,

Douglas

1 Like

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