Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
5 Trả lời
10298 Lượt xem

Hi,

I follow the docs: https://www.odoo.com/documentation/14.0/webservices/odoo.html

I am trying to make a test connection to demo as shown in the example: $info = ripcord::client('https://demo.odoo.com/start')->start();

Everything goes well. I get the host, database, username, and password.

When I call $common->version(); I get the correct response.

But when trying to $uid = $common->authenticate($db, $username, $password, array()); I get the following error:

Traceback (most recent call last): File "/home/odoo/src/odoo/14.0/odoo/addons/base/controllers/rpc.py", line 69, in xmlrpc_2 response = self._xmlrpc(service) File "/home/odoo/src/odoo/14.0/odoo/addons/base/controllers/rpc.py", line 49, in _xmlrpc result = dispatch_rpc(service, method, params) File "/home/odoo/src/odoo/14.0/odoo/http.py", line 140, in dispatch_rpc result = dispatch(method, params) File "/home/odoo/src/odoo/14.0/odoo/service/common.py", line 56, in dispatch return g[exp_method_name](*params) File "/home/odoo/src/odoo/14.0/odoo/service/common.py", line 27, in exp_authenticate return res_users.authenticate(db, login, password, {**user_agent_env, 'interactive': False}) TypeError: 'list' object is not a mapping

What am I doing wrong?

Ảnh đại diện
Huỷ bỏ
Tác giả

Thank you, Piotr!

This is a correct answer:

$common = ripcord::client("$url/xmlrpc/2/common");

$version = $common->version();

$uid = $common->authenticate($db, $username, $password, $version);

Câu trả lời hay nhất

Try to pass JSON as the last argument instead of an array.

$uid = $common->authenticate($db, $username, $password, {});


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

I had the same situation. In my case working solution:

$common = ripcord::client("$url/xmlrpc/2/common");
$version = $common->version();
$uid = $common->authenticate($db, $username, $password, $version);

Please confirm, if this solution works to you.

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

Thank you.

This will trigger PHP Parse error error: $uid = $common->authenticate($db, $username, $password, {});

I tried: $uid = $common->authenticate($db, $username, $password, "{}"); but it triggers similar error:

array(2) { ["faultCode"]=> int(1) ["faultString"]=> string(761) "Traceback (most recent call last): File "/home/odoo/src/odoo/14.0/odoo/addons/base/controllers/rpc.py", line 69, in xmlrpc_2 response = self._xmlrpc(service) File "/home/odoo/src/odoo/14.0/odoo/addons/base/controllers/rpc.py", line 49, in _xmlrpc result = dispatch_rpc(service, method, params) File "/home/odoo/src/odoo/14.0/odoo/http.py", line 140, in dispatch_rpc result = dispatch(method, params) File "/home/odoo/src/odoo/14.0/odoo/service/common.py", line 56, in dispatch return g[exp_method_name](*params) File "/home/odoo/src/odoo/14.0/odoo/service/common.py", line 27, in exp_authenticate return res_users.authenticate(db, login, password, {**user_agent_env, 'interactive': False}) TypeError: 'str' object is not a mapping " }
Any other thoughts?

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

I tried: $uid = $common->authenticate($db, $username, $password, "{}"); but it triggers similar error:

With the quote around the "{}", you give a string instead of a dict.

 

Actually, python needs a dict to be present (the {}) and it can be empty.

A JSON string will not work.


That part of the code did change recently, making it impossible to give an empty array.

The workaround is to give a named array like this:

array("a"=>"b")


A pull request is in progress to allow an empty array parameter as before.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

I am resolved the problem passing in to last parameter the value returned in the method Version. I am programming at C# y the code is this:

OdooVersion vVersion = XmlRpcProxyGen.Create<OdooVersion>(); 
vVersion.Url = this._UrlBase + "/xmlrpc/2/common"; 
object vResult = vVersion.version();
OdooAutenticar proyCall = XmlRpcProxyGen.Create<OdooAutenticar>();
proyCall.Url = this._UrlBase + "/xmlrpc/2/common";
 int vResult2 = proyCall.authenticate(this._BaseDatos.Trim() , this._Usuario.Trim(), this._Password.Trim(), vResult); 
 return vResult2; 

The error only occurs the version 14.
In the version 12 or 13 the call "Authenticate" method runs without problems
Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
4
thg 8 24
38552
0
thg 4 25
1003
0
thg 1 24
2478
0
thg 7 21
3165
0
thg 7 25
182