Response time using proteus and flask?

is there any work around that i could reduce the response time in tryton flask ?

here is my code hope i am doing this in right manner

from flask import Flask ,render_template, flash, redirect, url_for, session
from proteus import config, Model, Wizard, Report
from passlib.hash import sha256_crypt
import uuid 
from flask import request , jsonify


app = Flask(__name__)


@app.route('/register', methods=["POST"])
def register():
    configs = config.set_xmlrpc('http://admin:12345678@localhost:8000/health/')
    Party = Model.get('party.party')
    party = Party()
    party.name = request.json['name']
    party.emailuser = request.json['email']
    party.mobile = request.json['mobile'] 
    party.password = sha256_crypt.hash(request.json['password'])
    party.save()

    return {"success" : "Registered" }

You should not use proteus inside a flask_tryton.

Instead of:

You should use:

from flask_tryton import Tryton 
tryton = Tryton(app, configure_jinja=True)  
Party = tryton.pool.get('party.party')

This will provide direct access to the tryton database which will make the code much faster.

Thanks a lot for the reply @pokoli but i am getting the following error

    Traceback (most recent call last):
      File "/home/gnuhealth/.local/lib/python3.8/site-packages/flask/app.py", line 2447, in wsgi_app
        response = self.full_dispatch_request()
      File "/home/gnuhealth/.local/lib/python3.8/site-packages/flask/app.py", line 1952, in full_dispatch_request
        rv = self.handle_user_exception(e)
      File "/home/gnuhealth/.local/lib/python3.8/site-packages/flask/app.py", line 1821, in handle_user_exception
        reraise(exc_type, exc_value, tb)
      File "/home/gnuhealth/.local/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
        raise value
      File "/home/gnuhealth/.local/lib/python3.8/site-packages/flask/app.py", line 1950, in full_dispatch_request
        rv = self.dispatch_request()
      File "/home/gnuhealth/.local/lib/python3.8/site-packages/flask/app.py", line 1936, in dispatch_request
        return self.view_functions[rule.endpoint](**req.view_args)
      File "app3.py", line 14, in register
        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 66, in init_app
        self.pool = Pool(database)
      File "/home/gnuhealth/gnuhealth/tryton/server/trytond-5.0.27/trytond/pool.py", line 58, in __new__
        database_name = Transaction().database.name
    AttributeError: 'NoneType' object has no attribute 'name'

Edited : Just configured the database using the following code and it sorted out the above error

app.config['TRYTON_CONFIG'] = '/home/gnuhealth/gnuhealth/tryton/server/config/trytond.conf'
 
app.config['TRYTON_DATABASE'] = 'health'

Just configured the db but i cant get the logging disable . getting the following error

/home/gnuhealth/gnuhealth/tryton/server/trytond-5.0.27/trytond/wsgi.py:13: DeprecationWarning: The import 'werkzeug.wsgi.SharedDataMiddleware' is deprecated and will be removed in Werkzeug 1.0. Use 'from werkzeug.middleware.shared_data import SharedDataMiddleware' instead.
  from werkzeug.wsgi import SharedDataMiddleware
[2020-10-26 15:14:55,767] ERROR in app: Exception on /register [POST]
Traceback (most recent call last):
  File "/home/gnuhealth/.local/lib/python3.8/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/gnuhealth/.local/lib/python3.8/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/gnuhealth/.local/lib/python3.8/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/gnuhealth/.local/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/home/gnuhealth/.local/lib/python3.8/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/gnuhealth/.local/lib/python3.8/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "app3.py", line 17, in register
    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

any idea of disable the logging ?

It seems you have a default loggin set which is not valid.

You can clear it by setting and empty value for the TRYTOND_LOGGING_CONFIG environment variable.

i did try that but it does not solve the issue.The same error persist

even i tried running this code and same error persist

config.set_trytond(‘http://admin:12345678@localhost:8000/health/’)

where as this code works well

config.set_xmlrpc(‘http://admin:12345678@localhost:8000/health/’)

You should probably try to be more methodical.
When you try with a different setup, you should post again the error because you said it is the same. But we can not check, there may be differences that you do not see.
Also you should post the exact setup you tried.

This does not make sense. @pokoli told you to use flask_tryton and this is using proteus configuration.

I think your problem here is related to the vobject package. They seem to have made a change https://github.com/eventable/vobject/commit/84ddc247cce0cbdef408cfbd6cbe9653351a72fa, perhaps you need to update that package?

That was life saving @dave

Thanks

1 Like

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