使用Zeep过滤Magento SOAP请求

时间:2018-08-27 21:49:29

标签: python python-2.7 magento soap zeep

我正努力从Python 2.7向Magento的SOAP服务发送过滤器。我正在尝试使用Zeep包来调用SOAP服务。发送空列表作为第二个参数可以很好地返回所有数据。但是,当我在第二个参数中设置过滤器时,它将被忽略,并且我仍然会获取所有数据。预先感谢!

from zeep import Client

client = Client('https://mywebsite.com/api/v2_soap/index/?wsdl=1')

token = client.service.login('myusername', 'mypassword')

# This works fine, returns all of the customers
customer_list = client.service.customerCustomerList(token, [])

# This still returns all of the customers and ignores the filter
filter = [{'created_at': {'from': '2018-07-01 00:00:00'}}]
customer_list_filtered = client.service.customerCustomerList(token, filter)

我不确定是否相关,但是我收到了这些警告。

C:\Users\some_path_to_python\lib\site-packages\zeep\wsdl\wsdl.py:335: UserWarning: The wsdl:message for u'{urn:Magento}channelintegrationOrderInfoResponse' contains an invalid part ('result'): invalid xsd type or elements
  warnings.warn(str(exc))
C:\Users\some_path_to_python\lib\site-packages\zeep\wsdl\definitions.py:130: UserWarning: The wsdl:operation 'channelintegrationOrderInfo' was not found in the wsdl:portType u'{urn:Magento}PortType'
  warnings.warn(str(exc))

1 个答案:

答案 0 :(得分:0)

就我而言,我必须正确设置过滤器的格式。遵循文档中的示例-https://devdocs.magento.com/guides/m1x/api/soap/sales/salesOrder/sales_order.list.html#sales_order.list-Examples,我不得不编写这样的过滤器

filters = [{
    'filter': {
        'complexObjectArray': [{
            'key': 'status',
            'value': 'pending'
        }]
    },
    'complex_filter': {
        'complexObjectArray': [{
            'key': 'status',
            'value': {
                'key': 'in',
                'value': 'pending,processing'
            }
        }]
    }
}]

因此,换句话说,将所有内容包装在complexObjectArray中以使其正常工作。