تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
4154 أدوات العرض

When I use the ValidationError and UserError of odoo version 14 running on an ubuntu server to show the error to the user with an example statement like: 

 raise UserError(_('No API configuration parameter found. Please contact IT !')) 

but I get the error:

2023-05-14 05:55:10,281 20270 INFO his_odoo_v2 longpolling: 192.168.11.112 - - [2023-05-14 05:55:10] "POST /longpolling/im_status HTTP/1.0" 200 1961 0.015715 
2023-05-14 05:55:22,433 20270 INFO his_odoo_v2 longpolling: 192.168.11.112 - - [2023-05-14 05:55:22] "POST /longpolling/poll HTTP/1.0" 200 408 50.015951 
2023-05-14 05:55:33,193 20268 INFO his_odoo_v2 werkzeug: 172.10.1.103 - - [14/May/2023 05:55:33] "POST /longpolling/im_status HTTP/1.1" 200 - 5 0.009 0.011
2023-05-14 05:55:35,287 20270 INFO his_odoo_v2 longpolling: 192.168.11.112 - - [2023-05-14 05:55:35] "POST /longpolling/im_status HTTP/1.0" 200 1961 0.019660 
2023-05-14 05:55:37,276 20270 INFO his_odoo_v2 longpolling: 192.168.11.112 - - [2023-05-14 05:55:37] "POST /longpolling/im_status HTTP/1.0" 200 1961 0.015995 
2023-05-14 05:55:38,175 20267 INFO his_odoo_v2 werkzeug: 172.10.1.103 - - [14/May/2023 05:55:38] "POST /longpolling/poll HTTP/1.1" 500 - 1 0.000 0.003
2023-05-14 05:55:38,176 20267 ERROR his_odoo_v2 werkzeug: Error on request:
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/werkzeug/serving.py", line 306, in run_wsgi
execute(self.server.app)
File "/usr/local/lib/python3.8/dist-packages/werkzeug/serving.py", line 294, in execute
application_iter = app(environ, start_response)
File "/odoo/odoo-server/odoo/service/wsgi_server.py", line 113, in application
return application_unproxied(environ, start_response)
File "/odoo/odoo-server/odoo/service/wsgi_server.py", line 88, in application_unproxied
result = odoo.http.root(environ, start_response)
File "/odoo/odoo-server/odoo/http.py", line 1307, in __call__
return self.dispatch(environ, start_response)
File "/odoo/odoo-server/odoo/http.py", line 1273, in __call__
return self.app(environ, start_wrapped)
File "/usr/local/lib/python3.8/dist-packages/werkzeug/middleware/shared_data.py", line 220, in __call__
return self.app(environ, start_response)
File "/odoo/odoo-server/odoo/http.py", line 1502, in dispatch
return response(environ, start_response)
TypeError: 'NoneType' object is not callable - - -

I have tried, but still couldn't find the cause. I hope everyone can help me, thank you all very much. 

الصورة الرمزية
إهمال
أفضل إجابة

Hi,


It looks like you’re using UserError or ValidationError correctly in your code. The issue you're encountering—TypeError: 'NoneType' object is not callable—doesn't directly relate to how you're raising the exception, but might point to a deeper problem in your environment or code flow.


Here are a few things you can try:


Double-check your import

Make sure you're importing the exceptions properly at the top of your Python file:

python

from odoo.exceptions import UserError, ValidationError


Use the exception like this:


python

raise UserError(_('No API configuration parameter found. Please contact IT!'))


Check the full traceback

Sometimes, the actual cause of the NoneType error might be elsewhere in the function or in how the return is handled after raising the error. Ensure your method doesn't return None where a callable is expected.


You can also check out these helpful resources:


https://www.youtube.com/watch?v=eaP7J1oYmOo


https://www.cybrosys.com/blog/how-to-run-efficient-error-management-with-the-odoo-14-exceptions


Hope it helps

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
1
أكتوبر 24
1914
0
ديسمبر 23
1743
0
أبريل 21
2325
1
يونيو 20
4244
2
أبريل 17
31