python - Magento SOAP v1 过滤器不过滤(Python Suds)

标签 python api magento soap suds

更新如下

有没有人有适合 Magento SOAP v1 API 的 XML 示例来执行以下操作?

client.call(session_token,'sales_order.list', {'filters':{'order_id':{'eq':12}}})

这是对我不起作用的 python suds 调用示例。实际上,任何过滤 sales_order.list、catalog_product.list 或 customer.list 的示例 XML 都可以。我已经为 XMLRPC 版本工作了,但是使用 python 的 SUDS 和 SOAP v1 API,无论过滤器是什么,我都会得到未过滤的整个列表作为响应。这是 XML 当前的样子:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:ns3="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns2="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns4="urn:Magento" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Header/>
<ns1:Body>
<ns4:call>
<sessionId xsi:type="ns2:string">6634e1bd1004557677222fd81e809884</sessionId>
<resourcePath xsi:type="ns2:string">sales_order.list</resourcePath>
<args xsi:type="ns0:args">
<filters xsi:type="ns2:filters">
<order_id xsi:type="ns2:order_id">
<eq xsi:type="ns2:string">7</eq>
</order_id>
</filters>
</args>
</ns4:call>
</ns1:Body>

当然,我已经在上面尝试过上百万种其他变体。我只是想知道我的调用是否正确,我的模式是否错误,或者 soap 服务器是否不稳定,或者什么。因此,如果任何人有一些经过验证的正确 XML 可以尝试模拟,那将大有帮助。

谢谢!

更新:

根据到目前为止我收到的第一个答案,我实际上已经尝试过过滤器的格式。正如我们所知,Magento API 的文档是多种多样、相互矛盾且不完整的。这是 XML:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:ns3="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns2="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns4="urn:Magento" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Header/>
<ns1:Body>
<ns4:call>
<sessionId xsi:type="ns2:string">93c7aaab38adaab5db732b211e5b</sessionId>
<resourcePath xsi:type="ns2:string">sales_order.list</resourcePath>
<args xsi:type="ns0:args">
<filter xsi:type="ns2:filter">
<value xsi:type="ns2:string">123</value>
<key xsi:type="ns2:string">order_id</key>
</filter>
</args>
</ns4:call>
</ns1:Body>
</SOAP-ENV:Envelope>

或者可能:

<ns1:Body>
<ns4:call>
<sessionId xsi:type="ns2:string">93c74cb7ef0baaaaab5db732b211e5b</sessionId>
<resourcePath xsi:type="ns2:string">sales_order.list</resourcePath>
<args xsi:type="ns0:args">
<filter xsi:type="ns2:filter">
<value xsi:type="ns2:value">
<value xsi:type="ns2:string">123</value>
<key xsi:type="ns2:string">eq</key>
</value>
<key xsi:type="ns2:string">order_id</key>
</filter>
</args>
</ns4:call>
</ns1:Body>
</SOAP-ENV:Envelope>

看起来像这样:

{'filter':[{'key':'order_id','value':{'key':'eq','value':'123'}}]}

在 python 中。

那些仍然返回所有订单(最终......)。所以,正如我提到的,如果有人真的能给我一些 XML 来模拟,它可能会更有用。明天我可能会深入了解 Magento 源并解决我自己的问题。

最佳答案

好吧,我不得不刷掉(并学习)我的 PHP,但如果有任何其他可怜的 sap 出现并想将 SUDS(或一般的 python)与 Magento 一起使用,我在这里有答案。

这个 xml:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:Magento" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns2="http://xml.apache.org/xml-soap" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body><ns1:call><sessionId xsi:type="xsd:string">bc11488aaae84c841ac237ea7f24ef</sessionId>
<resourcePath xsi:type="xsd:string">sales_order.list</resourcePath>
<args SOAP-ENC:arrayType="ns2:Map[1]" xsi:type="SOAP-ENC:Array">
<item xsi:type="ns2:Map">
<item>
<key xsi:type="xsd:string">order_id</key>
<value xsi:type="ns2:Map">
<item>
<key xsi:type="xsd:string">from</key>
<value xsi:type="xsd:string">11</value>
</item>
<item>
<key xsi:type="xsd:string">to</key>
<value xsi:type="xsd:string">12</value>
</item>
</value>
</item>
</item>
</args>
</ns1:call>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

由这个 php 创建:

#! /usr/bin/php5
<?php
$client = new SoapClient('http://ip.ip.ip.ip/magento/index.php/api/?wsdl', array('trace'=>TRUE));
$session = $client->login('username', 'password');
$params = array(array(
        'order_id' =>
          array(
            'from' => '10',
            'to' => '12')));



$result = $client->call($session, 'sales_order.list', $params);
$resultXML = $client->__getLastRequest();
print($resultXML);
?>

当然,事实证明,围绕 Magento 协议(protocol)的特定实现,还存在各种与 SOAP 相关的编码问题——它似乎是为与 PHP Soap 客户端一起工作而设计的,但实际上并没有与其他任何东西一起工作。但是这个 XML 转储确实让我能够四处寻找并启动 SUDS 连接 - 如果您有兴趣,请给我发消息。哦,向@alanstorm 致敬。

关于python - Magento SOAP v1 过滤器不过滤(Python Suds),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12290684/

相关文章:

php - 如何通过 Magento API 创建可下载的产品?

python - 如何删除文件中每一行的一部分?

python3 queue.put() 阻塞 main

python - 如何处理巨大的 numpy 数组的计算以避免内存分配错误?

C#:如何添加名为 "protected"的类成员

api - 可以通过程序访问传感器读数的家庭气象站?

php - Magento fatal error :未找到类'Varien_Data_Collection_Filesystem'

python - pytorch下如何处理“CUDA内存不足”?

php - 如何从URL中获取hash(#)后的数据?

php - 如何在 magento 的类别页面上添加多个排序选项?