python - 使用 Zeep 过滤 Magento SOAP 请求
问题描述
我正在努力从 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))
解决方案
就我而言,我必须正确格式化过滤器。按照文档中的示例 - 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 中以使其工作。
推荐阅读
- python - python中的类扩展就像在swift中一样?
- python - 在python中将列表值一起添加?
- c++ - shared_ptr 在方法中填充的映射在调用者中返回为空
- angular - 如何导出角度项目以进行离线工作
- django - 在一篇文章中保存多个模型 - Django rest frameweok
- python - python CGI无需等待即可调用新的子进程
- javascript - 在`.then`之后没有运行Axios代码
- python - 在熊猫中使用带有元组列的查询
- batch-file - 将目录树复制到以今天日期命名的新目录
- spring - 一个 Spring 应用程序可以有两个 IoC 容器吗?