ajepe / odoo-addons

Odoo addons
24 stars 40 forks source link

Get error when trying example GET #17

Closed ladrua closed 3 years ago

ladrua commented 4 years ago

running the example GET in README to get orders result in following error:

2019-08-24 17:03:30,457 1 ERROR test werkzeug: Error on request:                                                                                               │b'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">\n<title>500 Internal Server Error</title>\n<h1>Internal Server Error</h1>\n<p>The server encountered
Traceback (most recent call last):                                                                                                                             │ an internal error and was unable to complete your request.  Either the server is overloaded or there is an error in the application.</p>\n'
  File "/usr/lib/python3/dist-packages/werkzeug/serving.py", line 205, in run_wsgi                                                                             │Done.
    execute(self.server.app)                                                                                                                                   │stian@db:/share/Projects/odoo$ python3 client.py list
  File "/usr/lib/python3/dist-packages/werkzeug/serving.py", line 193, in execute                                                                              │{'charset': 'utf-8', 'content-type': 'application/x-www-form-urlencoded', 'access-token': 'access_token_2d9bde458e7f4eb927b29e2096d2427b810d2ab6'}
    application_iter = app(environ, start_response)                                                                                                            │b'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">\n<title>500 Internal Server Error</title>\n<h1>Internal Server Error</h1>\n<p>The server encountered
  File "/usr/lib/python3/dist-packages/odoo/service/server.py", line 409, in app                                                                               │ an internal error and was unable to complete your request.  Either the server is overloaded or there is an error in the application.</p>\n'
    return self.app(e, s)                                                                                                                                      │Done.
  File "/usr/lib/python3/dist-packages/odoo/service/wsgi_server.py", line 128, in application                                                                  │stian@db:/share/Projects/odoo$ python3 client.py list
    return application_unproxied(environ, start_response)                                                                                                      │{'access-token': 'access_token_2d9bde458e7f4eb927b29e2096d2427b810d2ab6', 'charset': 'utf-8', 'content-type': 'application/x-www-form-urlencoded'}
  File "/usr/lib/python3/dist-packages/odoo/service/wsgi_server.py", line 117, in application_unproxied                                                        │b'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">\n<title>500 Internal Server Error</title>\n<h1>Internal Server Error</h1>\n<p>The server encountered
    result = odoo.http.root(environ, start_response)                                                                                                           │ an internal error and was unable to complete your request.  Either the server is overloaded or there is an error in the application.</p>\n'
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 1320, in __call__                                                                                   │Done.
    return self.dispatch(environ, start_response)                                                                                                              │stian@db:/share/Projects/odoo$ python3 client.py list
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 1293, in __call__                                                                                   │{'access-token': 'access_token_2d9bde458e7f4eb927b29e2096d2427b810d2ab6', 'charset': 'utf-8', 'content-type': 'application/x-www-form-urlencoded'}
    return self.app(environ, start_wrapped)                                                                                                                    │b'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">\n<title>500 Internal Server Error</title>\n<h1>Internal Server Error</h1>\n<p>The server encountered
  File "/usr/lib/python3/dist-packages/werkzeug/wsgi.py", line 599, in __call__                                                                                │ an internal error and was unable to complete your request.  Either the server is overloaded or there is an error in the application.</p>\n'
    return self.app(environ, start_response)                                                                                                                   │Done.
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 1488, in dispatch                                                                                   │stian@db:/share/Projects/odoo$
    result = ir_http._dispatch()                                                                                                                               │
  File "/usr/lib/python3/dist-packages/odoo/addons/website_sale/models/ir_http.py", line 15, in _dispatch                                                      │
    return super(IrHttp, cls)._dispatch()                                                                                                                      │
  File "/usr/lib/python3/dist-packages/odoo/addons/auth_signup/models/ir_http.py", line 19, in _dispatch                                                       │
    return super(Http, cls)._dispatch()                                                                                                                        │
  File "/usr/lib/python3/dist-packages/odoo/addons/web_editor/models/ir_http.py", line 22, in _dispatch                                                        │
    return super(IrHttp, cls)._dispatch()                                                                                                                      │
  File "/usr/lib/python3/dist-packages/odoo/addons/http_routing/models/ir_http.py", line 397, in _dispatch                                                     │
    result = super(IrHttp, cls)._dispatch()                                                                                                                    │
  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_http.py", line 207, in _dispatch                                                             │
    return cls._handle_exception(e)                                                                                                                            │
  File "/usr/lib/python3/dist-packages/odoo/addons/website/models/ir_http.py", line 195, in _handle_exception                                                  │
    return super(Http, cls)._handle_exception(exception)                                                                                                       │
  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_http.py", line 177, in _handle_exception                                                     │
    return request._handle_exception(exception)                                                                                                                │
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 776, in _handle_exception                                                                           │
    return super(HttpRequest, self)._handle_exception(exception)                                                                                               │
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 314, in _handle_exception                                                                           │
    raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])                                                                                      │
  File "/usr/lib/python3/dist-packages/odoo/tools/pycompat.py", line 87, in reraise                                                                            │
    raise value                                                                                                                                                │
  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_http.py", line 203, in _dispatch                                                             │
    result = request.dispatch()                                                                                                                                │
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 835, in dispatch                                                                                    │
    r = self._call_function(**self.params)                                                                                                                     │
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 346, in _call_function                                                                              │
    return checked_call(self.db, *args, **kwargs)                                                                                                              │
  File "/usr/lib/python3/dist-packages/odoo/service/model.py", line 97, in wrapper                                                                             │
    return f(dbname, *args, **kwargs)                                                                                                                          │
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 339, in checked_call                                                                                │
    result = self.endpoint(*a, **kw)                                                                                                                           │
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 941, in __call__                                                                                    │
    return self.method(*args, **kw)                                                                                                                            │
  File "/mnt/extra-addons/restful/controllers/main.py", line 46, in wrap                                                                                       │
    return func(self, *args, **kwargs)                                                                                                                         │
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 519, in response_wrap                                                                               │
    response = f(*args, **kw)                                                                                                                                  │
  File "/mnt/extra-addons/restful/controllers/main.py", line 66, in get                                                                                        │
    domain, fields, offset, limit, order = extract_arguments(payload)                                                                                          │
  File "/mnt/extra-addons/restful/common.py", line 56, in extract_arguments                                                                                    │
    except JSONDecodeError as e:                                                                                                                               │
NameError: name 'JSONDecodeError' is not defined - - -
ajepe commented 4 years ago

What version are using?

ladrua commented 4 years ago

Thanks for quick reply. Odoo version 12.0-20190816 Docker image.

ajepe commented 4 years ago

Alright I will take a look now

ladrua commented 4 years ago

I am able to create and recieve the token fine.

ajepe commented 4 years ago

Can you show me the request that lead to the error message, it will help to debug fast.

ladrua commented 4 years ago
req = requests.get('{}/api/sale.order/'.format(base_url), headers=headers,
                   data={'limit': 10, 'domain': []})
print(req.content)
ajepe commented 4 years ago

Thanks

ladrua commented 4 years ago

It might be something else, I am getting similar issues when using the XML-RPC protocol as well... weird.

ladrua commented 4 years ago

Disregard last comment. It is just when using the restful module.

ajepe commented 4 years ago

The issue is fixed download the latest update and put the domain inside a string like this

requests.get('{}/api/sale.order/'.format(base_url), headers=headers,data={'limit': 1, 'domain': "[('id', 'in',[2,1])]"})

Without the "" around the domain list it, the domain content will get strip off

ladrua commented 4 years ago

Thanks! Can confirm that it now works.

Jaquedeveloper commented 4 years ago

The issue is still present in the 11.0 version. Same issue, the fix didn't worked...

ajepe commented 4 years ago

Can help with the error message that you get

Jaquedeveloper commented 4 years ago

Sure

code:

import requests, json

headers = {
    'charset':'utf-8',
    'content-type': 'application/x-www-form-urlencoded',
}
data = {
    'login': 'login',
    'password': 'password',
    'db': 'db' 
}
base_url = 'http://192.168.1.100'

print('{}/api/auth/token'.format(base_url))

req = requests.get('{}/api/auth/token'.format(base_url), data=data, headers=headers)
# 200 - ok
content = json.loads(req.content.decode('utf-8'))

# add the access token to the headers
headers['access-token'] = content.get('access_token') 
req = requests.get('{}/api/sale.order/'.format(base_url), headers=headers,data={'limit': 1, 'domain': "[('id','in',[2,1])]"})

print(req)
# 500 - Bad request

server side:

2019-12-11 15:59:24,656 95014 INFO odoo-development-envirment werkzeug: 192.168.1.199 - - [11/Dec/2019 15:59:24] "GET /api/auth/token HTTP/1.1" 200 - 2019-12-11 15:59:24,738 95014 INFO odoo-development-envirment werkzeug: 192.168.1.199 - - [11/Dec/2019 15:59:24] "GET /api/sale.order/ HTTP/1.1" 500 - 2019-12-11 15:59:24,887 95014 ERROR odoo-development-envirment werkzeug: Error on request: Traceback (most recent call last): File "/usr/lib/python3/dist-packages/werkzeug/serving.py", line 205, in run_wsgi execute(self.server.app) File "/usr/lib/python3/dist-packages/werkzeug/serving.py", line 193, in execute application_iter = app(environ, start_response) File "/usr/lib/python3/dist-packages/odoo/service/wsgi_server.py", line 166, in application return application_unproxied(environ, start_response) File "/usr/lib/python3/dist-packages/odoo/service/wsgi_server.py", line 154, in application_unproxied result = handler(environ, start_response) File "/usr/lib/python3/dist-packages/odoo/http.py", line 1321, in call return self.dispatch(environ, start_response) File "/usr/lib/python3/dist-packages/odoo/http.py", line 1295, in call return self.app(environ, start_wrapped) File "/usr/lib/python3/dist-packages/werkzeug/wsgi.py", line 599, in call return self.app(environ, start_response) File "/usr/lib/python3/dist-packages/odoo/http.py", line 1493, in dispatch result = ir_http._dispatch() File "/usr/lib/python3/dist-packages/odoo/addons/auth_signup/models/ir_http.py", line 19, in _dispatch return super(Http, cls)._dispatch() File "/usr/lib/python3/dist-packages/odoo/addons/web_editor/models/ir_http.py", line 22, in _dispatch return super(IrHttp, cls)._dispatch() File "/usr/lib/python3/dist-packages/odoo/addons/http_routing/models/ir_http.py", line 396, in _dispatch result = super(IrHttp, cls)._dispatch() File "/usr/lib/python3/dist-packages/odoo/addons/base/ir/ir_http.py", line 212, in _dispatch return cls._handle_exception(e) File "/usr/lib/python3/dist-packages/odoo/addons/base/ir/ir_http.py", line 182, in _handle_exception return request._handle_exception(exception) File "/usr/lib/python3/dist-packages/odoo/http.py", line 773, in _handle_exception return super(HttpRequest, self)._handle_exception(exception) File "/usr/lib/python3/dist-packages/odoo/http.py", line 312, in _handle_exception raise pycompat.reraise(type(exception), exception, sys.exc_info()[2]) File "/usr/lib/python3/dist-packages/odoo/tools/pycompat.py", line 87, in reraise raise value File "/usr/lib/python3/dist-packages/odoo/addons/base/ir/ir_http.py", line 208, in _dispatch result = request.dispatch() File "/usr/lib/python3/dist-packages/odoo/http.py", line 832, in dispatch r = self._call_function(self.params) File "/usr/lib/python3/dist-packages/odoo/http.py", line 344, in _call_function return checked_call(self.db, *args, *kwargs) File "/usr/lib/python3/dist-packages/odoo/service/model.py", line 97, in wrapper return f(dbname, args, kwargs) File "/usr/lib/python3/dist-packages/odoo/http.py", line 337, in checked_call result = self.endpoint(*a, kw) File "/usr/lib/python3/dist-packages/odoo/http.py", line 939, in call return self.method(*args, *kw) File "/usr/lib/python3/dist-packages/odoo/custom-addons/restful/controllers/main.py", line 46, in wrap return func(self, args, kwargs) File "/usr/lib/python3/dist-packages/odoo/http.py", line 517, in response_wrap response = f(*args, **kw) File "/usr/lib/python3/dist-packages/odoo/custom-addons/restful/controllers/main.py", line 66, in get domain, fields, offset, limit, order = extract_arguments(payload) File "/usr/lib/python3/dist-packages/odoo/custom-addons/restful/common.py", line 54, in extract_arguments payload = json.loads(data) File "/usr/lib/python3.5/json/init.py", line 319, in loads return _default_decoder.decode(s) File "/usr/lib/python3.5/json/decoder.py", line 339, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python3.5/json/decoder.py", line 357, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) 2019-12-11 15:59:32,254 94016 INFO odoo-development-envirment odoo.modules.registry: Invalidating all model caches after database signaling.

ajepe commented 4 years ago

Can you try the module by cloning branch 12.0 it will work on Odoo v11.0

Jaquedeveloper commented 4 years ago

It worked! Thank you very much from Brazil!