Python 通过SOAP v2创建Magento产品

Python 通过SOAP v2创建Magento产品,python,magento,soap,suds,Python,Magento,Soap,Suds,我正在用Python实现一个通过SOAPV2与Magento交互的服务。到目前为止,我能够让产品列表执行以下操作: import suds from suds.client import Client wsdl_file = 'http://server/api/v2_soap?wsdl=1' user = 'user' password = 'password' client = Client(wsdl_file) # load the wsdl file session = client.s

我正在用Python实现一个通过SOAPV2与Magento交互的服务。到目前为止,我能够让产品列表执行以下操作:

import suds
from suds.client import Client
wsdl_file = 'http://server/api/v2_soap?wsdl=1'
user = 'user'
password = 'password'
client = Client(wsdl_file) # load the wsdl file
session = client.service.login(user, password) # login and create a session
client.service.catalogProductList(session)
但是,我无法创建产品,因为我不知道应该发送什么数据以及如何发送。我知道我必须使用的方法是catalogProductCreate,但所示的PHP示例并不能真正帮助我

如有任何意见,将不胜感激


提前谢谢你。

你已经到了。我认为您的问题是无法将PHP参数数组转换为Python键值对。如果是这样的话,这会对你有所帮助。还需要在创建产品之前使用catalogProductAttributeSetList设置属性集

    attributeSets = client.service.catalogProductAttributeSetList(session)
    #print attributeSets
    # Not very sure how to get the current element from the attributeSets array. hope the below code will work 
    attributeSet = attributeSets[0]
    product_details = [{'name':'Your Product Name'},{'description':'Product description'},{'short_description':'Product short description'},{'weight':'10'},{    'status':'1'},{'url_key':'product-url-key'},{'url_path':'product-url-path'},{'visibility' :4},{'price':100},{'tax_class_id':1},{'categories': [2]},{'websites': [1]}]
    client.service.catalogProductCreate(session , 'simple', attributeSet.set_id, 'your_product_sku',product_details) 

你已经到了。我认为您的问题是无法将PHP参数数组转换为Python键值对。如果是这样的话,这会对你有所帮助。还需要在创建产品之前使用catalogProductAttributeSetList设置属性集

    attributeSets = client.service.catalogProductAttributeSetList(session)
    #print attributeSets
    # Not very sure how to get the current element from the attributeSets array. hope the below code will work 
    attributeSet = attributeSets[0]
    product_details = [{'name':'Your Product Name'},{'description':'Product description'},{'short_description':'Product short description'},{'weight':'10'},{    'status':'1'},{'url_key':'product-url-key'},{'url_path':'product-url-path'},{'visibility' :4},{'price':100},{'tax_class_id':1},{'categories': [2]},{'websites': [1]}]
    client.service.catalogProductCreate(session , 'simple', attributeSet.set_id, 'your_product_sku',product_details) 
因为productData格式不正确。您可能想从
更改
product\u details=[{'name':'Your product name'},{'description':'product description'},{'short\u description':'product short description'},{'weight':'10'},{'status':'1'},{'url\u key':'product-url-key'},{'url\path':'product-url-path'},{'visibility':4},{'price':100},{'tax\u class\id':1},{'categories':[2]},{/code]>


product\u details={'name':'Your product name','description':'product description','short\u description':'product short description','weight':'10','status':'1','url\u key':'product-url-key','url-path':'product-url-path','visibility':4,'price':100,'tax\u class\u id':1,'categories':[2],'websites':[1]

它对我有用

因为productData格式不正确。您可能想从
更改
product\u details=[{'name':'Your product name'},{'description':'product description'},{'short\u description':'product short description'},{'weight':'10'},{'status':'1'},{'url\u key':'product-url-key'},{'url\path':'product-url-path'},{'visibility':4},{'price':100},{'tax\u class\id':1},{'categories':[2]},{/code]>


product\u details={'name':'Your product name','description':'product description','short\u description':'product short description','weight':'10','status':'1','url\u key':'product-url-key','url-path':'product-url-path','visibility':4,'price':100,'tax\u class\u id':1,'categories':[2],'websites':[1]


这对我很有用。

非常感谢,这对我真的很有帮助。但是,在服务调用之后,我收到了以下错误:
suds.TypeNotFound:Type notfound:'productData'
不客气;-)我不太确定是否可以进一步帮助您,因为我还没有使用python使用任何Web服务。。。基本上,您需要检查的是发送了什么请求以及得到了什么响应……我希望下面的线程能够在这方面进一步帮助您,非常感谢您,这对我真的很有帮助。但是,在服务调用之后,我收到了以下错误:
suds.TypeNotFound:Type notfound:'productData'
不客气;-)我不太确定是否可以进一步帮助您,因为我还没有使用python使用任何Web服务。。。基本上,您需要检查的是发送了什么请求以及得到了什么响应……我希望下面的线程能够进一步帮助您完成这一任务