Hello
i have been working with api along with proteus. i could work with proteus but the condition is that i must have to set config.set_xmlrpc(‘http://admin:12345678@localhost:8000/health/’) in every request . that increases the delay.. is there any workaround where i could reduce the response time
There is a bug opened (issue7783) about this slowness when using proteus in xmlrpc mode, which is related to login/password validation which is done with hash.
I have some code to authenticate with session cookie that I could share (but proper resolution of issue7783 would be fine, now that python3.8 is available).
For having to call config.set_xmlrpc() for every request, it seems odd. Do you have some example code ?
Here is the code
@app.route('/login', methods=['GET'])
def login(request):
configs = config.set_xmlrpc('http://admin:12345678@localhost:8000/health/')
Module = Model.get('party.party')
# party_module, = Module.find([('name', '=', 'saif')])
party = Module.find([('emailuser', '=', 'saif.kazi76@gmail.com')])
# party_module, = Module.find([('name', '=', 'party')])
return str(party[0].api_token)
It looks like you are developing a Flask application with Tryton as backend. You may consider flask-trtyon.
is it ok if i use proteus for crud operations along with flask ?
sorry for noob question
Yes for small usage. You will not be able to get all the performance of the Tryton’s ORM with proteus.
Thanks a lot for the solution i can’t find an example of how i can connect flask-tryton to postgresql. or should i use vanilla flask and connect it to postgresql
It connects using trytond and the configuration file defined by TRYTON_CONFIG.
i did give it a try using by installing flask but i am getting this error on my gnu health
Traceback (most recent call last):
File "app.py", line 6, in <module>
tryton = Tryton(app , configure_jinja=True)
File "/usr/local/lib/python3.8/dist-packages/flask_tryton.py", line 52, in __init__
self.init_app(app)
File "/usr/local/lib/python3.8/dist-packages/flask_tryton.py", line 66, in init_app
self.pool = Pool(database)
File "/usr/local/lib/python3.8/dist-packages/trytond/pool.py", line 60, in __new__
database_name = Transaction().database.name
AttributeError: 'NoneType' object has no attribute 'name'
here is my code
from flask import Flask
from flask_tryton import Tryton
app = Flask(__name__)
app.config['TRYTON_CONFIG'] = '/home/gnuhealth/gnuhealth/tryton/server/config/trytond.conf'
tryton = Tryton(app , configure_jinja=True)
app.run()
i am not sure what i am doing wrong
You must also set the TRYTON_DATABASE as flask-tryton is mono-database.
i just edited my code to set database
from flask import Flask
from flask_tryton import Tryton
app = Flask(__name__)
app.config['TRYTON_CONFIG'] = '/home/gnuhealth/gnuhealth/tryton/server/config/trytond.conf'
app.config['TRYTON_DATABASE'] = 'health'
tryton = Tryton(app , configure_jinja=True)
app.run()
but i am getting this error
> connection to "health" failed
> Traceback (most recent call last):
> File "/usr/local/lib/python3.8/dist-packages/trytond/backend/postgresql/database.py", line 174, in __new__
> inst._connpool = ThreadedConnectionPool(
> File "/usr/local/lib/python3.8/dist-packages/psycopg2/pool.py", line 161, in __init__
> AbstractConnectionPool.__init__(
> File "/usr/local/lib/python3.8/dist-packages/psycopg2/pool.py", line 59, in __init__
> self._connect()
> File "/usr/local/lib/python3.8/dist-packages/psycopg2/pool.py", line 63, in _connect
> conn = psycopg2.connect(*self._args, **self._kwargs)
> File "/usr/local/lib/python3.8/dist-packages/psycopg2/__init__.py", line 127, in connect
> conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
> psycopg2.OperationalError: FATAL: role "root" does not exist
>
> Traceback (most recent call last):
> File "app.py", line 6, in <module>
> tryton = Tryton(app , configure_jinja=True)
> File "/usr/local/lib/python3.8/dist-packages/flask_tryton.py", line 52, in __init__
> self.init_app(app)
> File "/usr/local/lib/python3.8/dist-packages/flask_tryton.py", line 67, in init_app
> with Transaction().start(database, user, readonly=True):
> File "/usr/local/lib/python3.8/dist-packages/trytond/transaction.py", line 107, in start
> database = backend.Database(database_name).connect()
> File "/usr/local/lib/python3.8/dist-packages/trytond/backend/postgresql/database.py", line 174, in __new__
> inst._connpool = ThreadedConnectionPool(
> File "/usr/local/lib/python3.8/dist-packages/psycopg2/pool.py", line 161, in __init__
> AbstractConnectionPool.__init__(
> File "/usr/local/lib/python3.8/dist-packages/psycopg2/pool.py", line 59, in __init__
> self._connect()
> File "/usr/local/lib/python3.8/dist-packages/psycopg2/pool.py", line 63, in _connect
> conn = psycopg2.connect(*self._args, **self._kwargs)
> File "/usr/local/lib/python3.8/dist-packages/psycopg2/__init__.py", line 127, in connect
> conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
> psycopg2.OperationalError: FATAL: role "root" does not exist
This means that the connection to the database is not properly configured.
“root” is not an existing user on the database. Probably you rely on local user to be trusted by PosgtreSQL and usually you run trytond with another user than “root”.
Thanks i was able to figured that out
file "app.py", line 6, in <module>
tryton = Tryton(app , configure_jinja=True)
File "/home/gnuhealth/.local/lib/python3.8/site-packages/flask_tryton.py", line 52, in __init__
self.init_app(app)
File "/home/gnuhealth/.local/lib/python3.8/site-packages/flask_tryton.py", line 68, in init_app
self.pool.init()
File "/home/gnuhealth/gnuhealth/tryton/server/trytond-5.0.27/trytond/pool.py", line 149, in init
self.start()
File "/home/gnuhealth/gnuhealth/tryton/server/trytond-5.0.27/trytond/pool.py", line 102, in start
register_classes()
File "/home/gnuhealth/gnuhealth/tryton/server/trytond-5.0.27/trytond/modules/__init__.py", line 331, in register_classes
the_module = import_module(module)
File "/home/gnuhealth/gnuhealth/tryton/server/trytond-5.0.27/trytond/modules/__init__.py", line 53, in import_module
module = importlib.import_module(fullname)
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/gnuhealth/gnuhealth/tryton/server/trytond-5.0.27/trytond/modules/calendar/__init__.py", line 16, in <module>
from .webdav import *
File "/home/gnuhealth/gnuhealth/tryton/server/trytond-5.0.27/trytond/modules/calendar/webdav.py", line 3, in <module>
import vobject
File "/home/gnuhealth/.local/lib/python3.8/site-packages/vobject/__init__.py", line 79, in <module>
from .base import newFromBehavior, readOne, readComponents
File "/home/gnuhealth/.local/lib/python3.8/site-packages/vobject/base.py", line 72, in <module>
formatter = logging.Formatter('{name} {levelname} {message}')
File "/usr/lib/python3.8/logging/__init__.py", line 576, in __init__
self._style.validate()
File "/usr/lib/python3.8/logging/__init__.py", line 429, in validate
raise ValueError("Invalid format '%s' for '%s' style" % (self._fmt, self.default_format[0]))
ValueError: Invalid format '{name} {levelname} {message}' for '%' style
but the following issue raises
This is no more related to flask or proteus topic.
You seem to have compatibility issue between the non-standard calendar module and the vobject library.
This seems an error due to a invalid format defined on your logging configuration.
If you disable the logging you should probably be able to runt he server.