# Proteus connecting to postgres

**URL:** <https://discuss.tryton.org/t/proteus-connecting-to-postgres/2902>\
**Category:** User\
**Created:** [June 20, 2020, 6:19pm UTC](https://discuss.tryton.org/t/proteus-connecting-to-postgres/2902 "2020-06-20T18:19:18Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![douglas](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/d/a6a055/32.png) [@douglas](https://discuss.tryton.org/u/douglas)\
**Post date:** [June 20, 2020, 6:19pm UTC](https://discuss.tryton.org/t/proteus-connecting-to-postgres/2902/1 "2020-06-20T18:19:18Z")

</div>

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

```

---

<div class="post-metadata">

**Author:** ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)\
**Post date:** [June 20, 2020, 7:06pm UTC](https://discuss.tryton.org/t/proteus-connecting-to-postgres/2902/2 "2020-06-20T19:06:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![douglas](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/d/a6a055/32.png) [@douglas](https://discuss.tryton.org/u/douglas)\
**Post date:** [June 20, 2020, 7:33pm UTC](https://discuss.tryton.org/t/proteus-connecting-to-postgres/2902/3 "2020-06-20T19:33:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)\
**Post date:** [June 20, 2020, 7:54pm UTC](https://discuss.tryton.org/t/proteus-connecting-to-postgres/2902/4 "2020-06-20T19:54:18Z")

</div>

> [@douglas](#):
>
> I am unaware of what an ‘entrypoint’

See [Dockerfile reference | Docker Docs](https://docs.docker.com/engine/reference/builder/#entrypoint)

So how are you launching this script in docker.

---

<div class="post-metadata">

**Author:** ![dave](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/d/ee7513/32.png) [@dave](https://discuss.tryton.org/u/dave)\
**Post date:** [June 21, 2020, 10:30am UTC](https://discuss.tryton.org/t/proteus-connecting-to-postgres/2902/6 "2020-06-21T10:30:21Z")

</div>

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](https://bugs.tryton.org/issue9365) 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](https://docs.python.org/3.8/library/urllib.parse.html#urllib.parse.quote) any special characters in your password):

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

```

---

<div class="post-metadata">

**Author:** ![douglas](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/d/a6a055/32.png) [@douglas](https://discuss.tryton.org/u/douglas)\
**Post date:** [June 21, 2020, 11:01am UTC](https://discuss.tryton.org/t/proteus-connecting-to-postgres/2902/7 "2020-06-21T11:01:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dave](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/d/ee7513/32.png) [@dave](https://discuss.tryton.org/u/dave)\
**Post date:** [June 21, 2020, 11:23am UTC](https://discuss.tryton.org/t/proteus-connecting-to-postgres/2902/8 "2020-06-21T11:23:57Z")

</div>

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 — Library to access Tryton server as a client](https://docs.tryton.org/projects/client-library/en/latest/)

---

<div class="post-metadata">

**Author:** ![douglas](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/d/a6a055/32.png) [@douglas](https://discuss.tryton.org/u/douglas)\
**Post date:** [June 21, 2020, 11:34am UTC](https://discuss.tryton.org/t/proteus-connecting-to-postgres/2902/11 "2020-06-21T11:34:15Z")

</div>

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

Thank you,

Douglas

---

<div class="post-metadata">

**Author:** ![system](https://discuss-cdn.tryton.org/uploads/default/original/1X/c6f8ec0a40525cdcd50058c734283450a4b3d38b.png) [@system](https://discuss.tryton.org/u/system)\
**Post date:** [July 21, 2020, 11:34am UTC](https://discuss.tryton.org/t/proteus-connecting-to-postgres/2902/12 "2020-07-21T11:34:21Z")

</div>

Closed on July 21, 2020, 11:34am UTC

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