Flask_Tryton and Tryton app

Hello everyone

Is it possible to have a flask application that needs to communicate with tryton and that is located outside the virtual machine where tryton is installed?
I’ve tried to configure it properly but I’m aiming at this level.

Here is the error and the configuration.

  1. Configuration
# create and configure the app
app = Flask(__name__)
app.config.from_object(__name__+'.ConfigClass')
app.config['TRYTON_CONFIG'] = 'http://172.17.0.7:2050/home/gnuhealth/gnuhealth/tryton/server/config/trytond.conf'
#app.config['TRYTON_CONFIG'] = '/home/gnuhealth/gnuhealth/tryton/server/config/trytond.conf'
app.config['TRYTON_DATABASE'] = 'postgresql://gnuhealth:toor@172.17.0.7:2051/PDMD_SANTE'
#app.config['TRYTON_DATABASE'] = 'pdmd_sante'
app.config['TRYTON_USER'] = 0
app.config['CORS_HEADERS'] = 'Content-Type'

db = SQLAlchemy(app)

CORS(app, resources={r"*": {"origins": "*"}})

print("L'application app ----------------- ", app.config)
  1. Error when i start the flask application
WARNING: Flask-User TokenManager: SECRET_KEY is shorter than 32 bytes.
could not load http://172.17.0.7:2050/home/gnuhealth/gnuhealth/tryton/server/config/trytond.conf
Traceback (most recent call last):
  File "/home/gnuhealth/Flask/flaskvenv/bin/flask", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/gnuhealth/Flask/flaskvenv/lib/python3.12/site-packages/flask/cli.py", line 1054, in main
    cli.main()
  File "/home/gnuhealth/Flask/flaskvenv/lib/python3.12/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/home/gnuhealth/Flask/flaskvenv/lib/python3.12/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gnuhealth/Flask/flaskvenv/lib/python3.12/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gnuhealth/Flask/flaskvenv/lib/python3.12/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gnuhealth/Flask/flaskvenv/lib/python3.12/site-packages/click/decorators.py", line 92, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gnuhealth/Flask/flaskvenv/lib/python3.12/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gnuhealth/Flask/flaskvenv/lib/python3.12/site-packages/flask/cli.py", line 918, in run_command
    raise e from None
  File "/home/gnuhealth/Flask/flaskvenv/lib/python3.12/site-packages/flask/cli.py", line 904, in run_command
    app = info.load_app()
          ^^^^^^^^^^^^^^^
  File "/home/gnuhealth/Flask/flaskvenv/lib/python3.12/site-packages/flask/cli.py", line 308, in load_app
    app = locate_app(import_name, name)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gnuhealth/Flask/flaskvenv/lib/python3.12/site-packages/flask/cli.py", line 218, in locate_app
    __import__(module_name)
  File "/home/gnuhealth/Flask/DoctorAPI/__init__.py", line 106, in <module>
    tryton = Tryton(app)
             ^^^^^^^^^^^
  File "/home/gnuhealth/Flask/flaskvenv/lib/python3.12/site-packages/flask_tryton.py", line 25, in __init__
    self.init_app(app)
  File "/home/gnuhealth/Flask/flaskvenv/lib/python3.12/site-packages/flask_tryton.py", line 42, in init_app
    with Transaction().start(database, user, readonly=True):
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gnuhealth/Flask/flaskvenv/lib/python3.12/site-packages/trytond/transaction.py", line 218, in start
    self.stop(False)
  File "/home/gnuhealth/Flask/flaskvenv/lib/python3.12/site-packages/trytond/transaction.py", line 237, in stop
    self.rollback()
  File "/home/gnuhealth/Flask/flaskvenv/lib/python3.12/site-packages/trytond/transaction.py", line 355, in rollback
    for datamanager in self._datamanagers:
                       ^^^^^^^^^^^^^^^^^^
AttributeError: 'Transaction' object has no attribute '_datamanagers'

Please someone can healp me?

flask-tryton need to have trytond package and an access to the database.

If you do not want that, you must use something else and communicate with the RPC like XML-RPC or JSON-RPC.

There is REST API for user application to ease such design but it is not yet implemented.

I want to have access to the database, but as soon as I put my flask application inside a machine containing the tryton installation, I get an error and I can no longer access and connect to the tryton application.

Traceback (most recent call last):
  File "/trytond/res/user.py", line 710, in check_password
    return CRYPT_CONTEXT.verify_and_update(password, hash_)
  File "/passlib/context.py", line 2422, in verify_and_update
    record = self._get_or_identify_record(hash, scheme, category)
  File "/passlib/context.py", line 2031, in _get_or_identify_record
    return self._identify_record(hash, category)
  File "/passlib/context.py", line 1132, in identify_record
    raise exc.UnknownHashError("hash could not be identified")
passlib.exc.UnknownHashError: hash could not be identified

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/trytond/wsgi.py", line 117, in dispatch_request
    return endpoint(request, **request.view_args)
  File "/trytond/protocols/dispatcher.py", line 46, in rpc
    return methods.get(request.rpc_method, _dispatch)(
  File "/trytond/protocols/dispatcher.py", line 61, in login
    session = security.login(
  File "/trytond/security.py", line 33, in login
    user_id = User.get_login(loginname, parameters)
  File "/trytond/res/user.py", line 667, in get_login
    user_ids.add(func(login, parameters))
  File "/trytond/res/user.py", line 683, in _login_password
    valid, new_hash = cls.check_password(password, password_hash)
  File "/trytond/res/user.py", line 716, in check_password
    valid = getattr(cls, 'check_' + hash_method)(password, hash_)
AttributeError: type object 'res.user' has no attribute 'check_'

You do not have the proper extra requirements for passlib to check the hashed password.
You need to check which hash method is used and install the required dependencies.

I don’t understand.

Which hash method is use on my flask application or tryton application?
because my tryton application was fine until I put the flask application inside it

I do not know it is passlib that pick the best one available.

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