无法使用PHP 7 XML-RPC访问Odoo外部API-访问被拒绝,致命错误

tvz2xvvm  于 2023-01-08  发布在  PHP
关注(0)|答案(2)|浏览(195)

我想在我的网站上使用Odoo的外部API,使用PHP 7。
就像Odoo's documentation中所说的,我已经把Ripcord library放在我的httpdocs中,我还在我的服务器上激活了XML RPC扩展OpenSSL已经激活,网站甚至是安全的(地址栏中有锁图标)。
我想在购买许可证之前用Odoo Demo Trial测试一下,所以在我的PHP代码中,我把username/password和我用来连接my Odoo demo accountusername/password放在了一起。

    • 1 °)**但我得到了faultCodefaultString(访问被拒绝)
$url = 'https://lgb-test.odoo.com';  // Odoo Demo Trial
$db = 'lgb-test';
$username = 'johndoe@mywebsiteexample.com';  // Same Email as the one to connect to https://lgb-test.odoo.com/web/login
$password = 'mypasswordexample';  // Same Password as the one to connect to https://lgb-test.odoo.com/web/login

require_once('ripcord/ripcord.php');

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

echo('UID:');
var_dump($uid);
echo('<br/>');

$models = ripcord::client("$url/xmlrpc/2/object");
$partners = $models->execute_kw(
    $db,
    $uid,
    $password,
    'res.partner',
    'search',
    array(
        array(
            array('is_company', '=', true)
        )
    )
);

echo('RESULT:<br/>');
foreach ($partners as $partner) {
    echo 'partner=['.$partner.']<br/>';
}
 
echo('VAR_DUMP:<br/>');
var_dump($partners);

输出:

UID:bool(false)
RESULT:
partner=[3]
partner=[Access Denied]
VAR_DUMP:
array(2) { ["faultCode"]=> int(3) ["faultString"]=> string(13) "Access Denied" }
    • 2 °)**当调用start()方法时,我得到Fatal error: Uncaught Ripcord_TransportException: Could not access
require_once('ripcord/ripcord.php');        
$info = ripcord::client('https://lgb-test.odoo.com/start/')->start();

echo 'hello';

输出:

Fatal error: Uncaught Ripcord_TransportException: Could not access https://lgb-test.odoo.com/start/ in /var/www/vhosts/mywebsiteexample.com/preprod.mywebsiteexample.com/ripcord/ripcord_client.php:488 Stack trace: #0 /var/www/vhosts/mywebsiteexample.com/preprod.mywebsiteexample.com/ripcord/ripcord_client.php(228): Ripcord_Transport_Stream->post('https://lgb-tes...', '<?xml version="...') #1 /var/www/vhosts/mywebsiteexample.com/preprod.mywebsiteexample.com/index.php(10): Ripcord_Client->__call('start', Array) #2 {main} thrown in /var/www/vhosts/mywebsiteexample.com/preprod.mywebsiteexample.com/ripcord/ripcord_client.php on line 488

(可能有类似的帖子,但有点模糊:
如何使用PHP7 Ripcord库获取Odoo数据?
Odoo + Ripcord PHP XMLRPC library: "Could not access https://demo.odoo.com/start"
所以,我还是不知道真正的问题是什么。
你知道吗?

pobjuy32

pobjuy321#

    • 1 °)经过一段时间的寻找解决方案,我终于决定购买一些模块**,而不是使用Odoo模拟帐户。

因此,我只是更改了新数据库的凭据,并且为该特定URL打开了8069端口
代码:

$url = 'https://thedatabasename.odoo.com';  // Edited here. Opening the 8069 port was the last step to make it work :)
$db = 'thedatabasename';                // Edited here
$username = 'usernameofthataccount';    // Edited here
$password = 'passwordofthataccount';    // Edited here

require_once('ripcord/ripcord.php');

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

echo('UID:');
var_dump($uid);
echo('<br/>');

$models = ripcord::client("$url/xmlrpc/2/object");
$partners = $models->execute_kw(
    $db,
    $uid,
    $password,
    'res.partner',
    'search',
    array(
        array(
            array('is_company', '=', true)
        )
    )
);

echo('RESULT:<br/>');
foreach ($partners as $partner) {
    echo 'partner=['.$partner.']<br/>';
}
 
echo('VAR_DUMP:<br/>');
var_dump($partners);

输出:

UID:int(2)
RESULT:
partner=[568]
partner=[570]
partner=[293]
partner=[378]
partner=[526]
VAR_DUMP:
array(193) { [0]=> int(568) [1]=> int(570) [2]=> int(293) [3]=> int(378) [4]=> int(526)}
    • 2 °)*start()方法无法用于特定URL

因此,我不确定start()方法是否适用于模拟账户以外的其他账户。
而且,Odoo的支持告诉我不要在脚本中包含URL的"
/start
"部分,但是,不管有没有"/start"部分,它都不起作用。
代码:

require_once('ripcord/ripcord.php');
$info = ripcord::client('https://thedatabasename.odoo.com/start')->start(); // Even using the specific IP, this is ot working in my case

echo 'hello';

输出:

Fatal error: Uncaught Ripcord_TransportException: Could not access http://102.16.10.74:8069/start/ in /var/www/vhosts/mywebsiteexample.com/preprod.mywebsiteexample.com/ripcord/ripcord_client.php:488 Stack trace: #0 /var/www/vhosts/mywebsiteexample.com/preprod.mywebsiteexample.com/ripcord/ripcord_client.php(228): Ripcord_Transport_Stream->post('http://102.16.1...', '<?xml version="...') #1 /var/www/vhosts/mywebsiteexample.com/preprod.mywebsiteexample.com/index.php(11): Ripcord_Client->__call('start', Array) #2 {main} thrown in /var/www/vhosts/mywebsiteexample.com/preprod.mywebsiteexample.com/ripcord/ripcord_client.php on line 488
    • 我的结论是**

Odoo演示对我没有起作用,即使我从这里按照指示操作:
Odoo's documentation

    • 编辑:**
      1°) a/We can get an IP Address (url is like "http://xxx.xxx.xxx.xxx") when we install manually our odoo server onto a different host server of our choice.
      1°) b/But if the odoo server is installed onto Odoo's official website (url is like "https://thedatabasename.odoo.com"), we haveno IP Address. And I managed to open the 8069 port
      by asking for it to the web host support
      of my website.

So, to make it simple, I edited "http://xxx.xxx.xxx.xxx" to "https://thedatabasename.odoo.com", for the case1°) b/:

$url = 'https://thedatabasename.odoo.com';
$db = 'thedatabasename';
z31licg0

z31licg02#

在我的例子中,有大数据被获取,这就是为什么odoo在JSONRPCXMLRPC上返回访问错误,所以我在执行函数时使用了limit关键字。
[“偏移量”=〉1,“限值”=〉50]

相关问题