Data Base - importing countries or currencies

Hello,
Question from a newbie
Context : Windows 10 Home / WSL 2 / Ubuntu 20.04 ; tryton:latest installed successfully using the docker procedure ; tryton is now « localhost :8000 » accessible

Executing in my « home » directory :

  • Command : TRYTOND_DATABASE_URI=‘postgresql://tryton:5432/tryton’ trytond_import_countries -d ‘postgresql://tryton:5432/tryton’
    Response : trytond_import_countries.py: command not found
  • Command : docker run --rm -ti tryton/tryton --pyrun trytond_import_countries.py
    Response : open(“trytond_import_countries.py”): No such file or directory [plugins/python/python_plugin.c line 1795]

Thank you, Marc

The name of the import script does not have .py, see: Setup — trytond_country latest documentation

Both Run #1 & #2 give no result in browser after refresh
Run #1:
docker run --rm -ti tryton/tryton --pyrun trytond_import_countries -d ‘postgresql://tryton:5432/tryton’
[uWSGI] getting INI configuration from /etc/uwsgi.conf
Run #2
postgres@LAPTOP-U8FF0ITJ:~$ docker run --rm -ti tryton/tryton --pyrun trytond_import_countries
[uWSGI] getting INI configuration from /etc/uwsgi.conf

Run #3 (adding “-c trytond.conf”) : error message
docker run --rm -ti tryton/tryton --pyrun trytond_import_countries -d ‘postgresql://tryton:5432/tryton’ -c trytond.conf
[uWSGI] getting INI configuration from /etc/uwsgi.conf
unable to load configuration from trytond.conf

Run #4 (adding reference to DB) : error message
docker run --rm -ti tryton/tryton --pyrun TRYTOND_DATABASE_URI=‘postgresql://tryton:5432/tryton’ trytond_import_countries -d ‘postgresql://tryton:5432/tryton’
[uWSGI] getting INI configuration from /etc/uwsgi.conf
unable to load configuration from trytond_import_countries

Thank you.

I do not know what is this --pyrun option. It is not a standard docker option.
Also the value of the --database option should be the database name only.

So you should run:

$ docker run --rm -ti tryton/tryton trytond_import_countries -d tryton

supposing that volumes and network are correctly configured.

1 Like

I get could not translate host name “postgres”: name or servce not known when following that last reply.
I have the same issue as the OP.
I followed the docker instructions exactly, same db, same container etc

Found the answer in another topic.
need to use:

docker exec --interactive --tty tryton /entrypoint.sh python3 -m \ trytond.modules.country.scripts.import_countries -d tryton

Running the below, won’t find postgres even if the full uri is supplied:

$ docker run --rm -ti tryton/tryton trytond_import_countries -d tryton

If the above two commands are supposed to be equivalent, they currently are not as of the latest docker commit.

1 Like

Context : WIndows 10 Home - PowerShell 7.0.0-rc.1 Admin - Docker - Tryton (2021-02-21)

Confirmed working :
import currencies

docker exec --interactive --tty tryton /entrypoint.sh python3 -m trytond.modules.currency.scripts.import_currencies -d tryton

import countries

docker exec --interactive --tty tryton /entrypoint.sh python3 -m trytond.modules.country.scripts.import_countries -d tryton

Thank you Mark !

Marc

1 Like

These two commands are not exactly equivalent…

  • docker exec runs the command inside an existing container, whereas
  • docker run creates a new container and runs the command inside that

This difference means that, in this case, the environment that the commands are running in is slightly different.

If you followed the How to run Tryton using Docker guide, then you should also find the following commands work:

docker exec --interactive --tty tryton /entrypoint.sh trytond_import_countries -d tryton

And:

docker run --rm --interactive --tty --env DB_HOSTNAME=tryton-postgres --env DB_PASSWORD=${POSTGRES_PASSWORD} --network tryton tryton/tryton trytond_import_countries -d tryton

Thanks for pointing that out ! So to be complete :

  • my commands were indeed run towards “existing started” tryton container

  • Also worked as per your suggestion :
    docker exec --interactive --tty tryton /entrypoint.sh trytond_import_countries -d tryton
    docker exec --interactive --tty tryton /entrypoint.sh trytond_import_currencies -d tryton

  • docker version 20.10.2

  • suggestion from a newbie : best to run the above commands (in whatever format) after installing Tryton and before using other functions (companies, sales, etc.)

2 Likes

Thanks, I don’t know much about Docker at all and the Tryton Docker guide doesn’t go into detail about how to run commands that are documented in the regular documentation.
Knowing it needs to be docker exec --… is going to be a great help.

I appreciate the explanation.

1 Like

Can somebody help please ?
I could successfully update currencies but not countries.

Here is the message :

PS C:\WINDOWS\system32> docker exec --interactive --tty tryton /entrypoint.sh trytond_import_countries -d tryton
/usr/lib/python3/dist-packages/zeep/loader.py:5: DeprecationWarning: defusedxml.lxml is no longer supported and will be removed in a future release.
  from defusedxml.lxml import fromstring
Traceback (most recent call last):
  File "/usr/local/bin/trytond_import_countries", line 8, in <module>
    sys.exit(run())
  File "/usr/local/lib/python3.9/dist-packages/trytond/modules/country/scripts/import_countries.py", line 563, in run
    main(args.database, args.config_file)
  File "/usr/local/lib/python3.9/dist-packages/trytond/modules/country/scripts/import_countries.py", line 541, in main
    do_import()
  File "/usr/local/lib/python3.9/dist-packages/trytond/modules/country/scripts/import_countries.py", line 545, in do_import
    countries = get_countries()
  File "/usr/local/lib/python3.9/dist-packages/trytond/modules/country/scripts/import_countries.py", line 390, in get_countries
    Country = Model.get('country.country')
  File "/usr/local/lib/python3.9/dist-packages/proteus/__init__.py", line 768, in get
    class Spam(Model, metaclass=MetaModelFactory(name, config=config)()):
  File "/usr/local/lib/python3.9/dist-packages/proteus/__init__.py", line 488, in __new__
    proxy = self.config.get_proxy(self.model_name)
  File "/usr/local/lib/python3.9/dist-packages/proteus/config.py", line 299, in get_proxy
    return TrytondProxy(name, self, type=type)
  File "/usr/local/lib/python3.9/dist-packages/proteus/config.py", line 225, in __init__
    self._object = config.pool.get(name, type=type)
  File "/usr/local/lib/python3.9/dist-packages/trytond/pool.py", line 188, in get
    return self._pool[self.database_name][type][name]
KeyError: 'country.country'

It looks like the country module is not activated on your tryton database.

1 Like

It was exactly that.
I started over my setup and forgot to activate it.
Thanks for the super quick answer.