【发布时间】:2016-06-22 14:16:24
【问题描述】:
所以我尝试使用 xmlrpc API 在 Python 中以编程方式创建 Magento 类别。
我是 Python 新手,这是我用 Python 编写的第一个严肃程序。
我不确定这是否与我的代码有关,但我会试一试。
这是我的代码:
from xmlrpc import client as cl
import pprint
proxy = cl.ServerProxy('http://example.com/index.php/api/xmlrpc/', allow_none=True)
session = proxy.login('api_user','api_key')
#PARAMS
name = 'Python Category'
path = ''
description = 'Inserted with my app'
meta_title = 'Python Category'
meta_keywords = 'Cool , Cat'
meta_description = 'Search robots will find this'
landing = ''
display = ''
active = 1
layout = ''
listing = {
'name' : name,
'is_active' : active,
'position' : 1,
'available_sort_by' : None,
'custom_design' : None,
'custom_apply_to_products' : None,
'custom_design_from' : None,
'custom_design_to' : None,
'custom_layout_update' : None,
'default_sort_by' : None,
'description' : description,
'display_mode' : display,
'is_anchor' : 0,
'landing_page' : landing,
'meta_description' : meta_description,
'meta_keywords' : meta_keywords,
'meta_title' : meta_title,
'page_layout' : '',
'url_key' : path,
'include_in_menu' : 1}
pprint.pprint(proxy.call(session, 'catalog_category.create', [listing]))
所以我有点怀疑pprint.pprint(proxy.call(session, 'catalog_category.create', [listing]))
我不知道我在怀疑什么,但在数组中列出对我来说似乎很不自然。
所以我的代码产生了这个错误:
Traceback (most recent call last):
File "C:\Users\Eigenaar\Desktop\connect.py", line 44, in <module>
pprint.pprint(proxy.call(session, 'catalog_category.create', [listing]))
File "C:\Users\Eigenaar\AppData\Local\Programs\Python\Python35-32\lib\xmlrpc\client.py", line 1091, in __call__
return self.__send(self.__name, args)
File "C:\Users\Eigenaar\AppData\Local\Programs\Python\Python35-32\lib\xmlrpc\client.py", line 1431, in __request
verbose=self.__verbose
File "C:\Users\Eigenaar\AppData\Local\Programs\Python\Python35-32\lib\xmlrpc\client.py", line 1133, in request
return self.single_request(host, handler, request_body, verbose)
File "C:\Users\Eigenaar\AppData\Local\Programs\Python\Python35-32\lib\xmlrpc\client.py", line 1149, in single_request
return self.parse_response(resp)
File "C:\Users\Eigenaar\AppData\Local\Programs\Python\Python35-32\lib\xmlrpc\client.py", line 1321, in parse_response
return u.close()
File "C:\Users\Eigenaar\AppData\Local\Programs\Python\Python35-32\lib\xmlrpc\client.py", line 654, in close
raise Fault(**self._stack[0])
xmlrpc.client.Fault: <Fault 1: "SQLSTATE[21000]: Cardinality violation: 1241 Operand should contain 1 column(s), query was: SELECT `mg_catalog_category_entity`.* FROM `mg_catalog_category_entity` WHERE (entity_id ='Cool , Cat', 'Python Category', 'Search robots will find this', '', '', 'Python Category', 1, '', '', 0, '', '', '', '', 1, 'Inserted with my app', '', '', '', 1)">
我认为这也可能与我尝试插入的值有关。
任何意见,将不胜感激。 Python 的精彩指南也不例外!
【问题讨论】:
标签: python sql magento xml-rpc