2014-11-03 45 views
2

我試過以下代碼。其他API在工作,只有customerCustomerList不工作​​..Magento無法列出客戶

def main(): 
    client = SOAPpy.WSDL.Proxy(WSDL_ADDR) 
    sid = client.login(username=USERNAME,apiKey=APIKEY) 
    print 'Logined as session id %s' % sid 

    print 'Listing customers...' 
    res = client.customerCustomerList(sid) 
    print res 

    client.endSession(sessionId=sid) 

而且它提供了以下異常:

/usr/local/lib/python2.7/site-packages/SOAPpy/Client.pyc in __call__(self, *args, **kw) 
    545      return self.__f_call(*args, **kw) 
    546    else: 
--> 547     return self.__r_call(*args, **kw) 
    548 
    549   def __getattr__(self, name): 

/usr/local/lib/python2.7/site-packages/SOAPpy/Client.pyc in __r_call(self, *args, **kw) 
    567   def __r_call(self, *args, **kw): 
    568    return self.__call(self.__name, args, kw, self.__ns, self.__sa, 
--> 569     self.__hd, self.__ma) 
    570 
    571   def __repr__(self): 

/usr/local/lib/python2.7/site-packages/SOAPpy/Client.pyc in __call(self, name, args, kw, ns, sa, hd, ma) 
    469 
    470 
--> 471   p, attrs = parseSOAPRPC(r, attrs = 1) 
    472 
    473   try: 

/usr/local/lib/python2.7/site-packages/SOAPpy/Parser.pyc in parseSOAPRPC(xml_str, header, body, attrs, rules, ignore_ext) 
    1103 def parseSOAPRPC(xml_str, header = 0, body = 0, attrs = 0, rules = None, ignore_ext=None): 
    1104 
-> 1105  t = _parseSOAP(xml_str, rules = rules, ignore_ext=ignore_ext) 
    1106  p = t.body[0] 
    1107 

/usr/local/lib/python2.7/site-packages/SOAPpy/Parser.pyc in _parseSOAP(xml_str, rules, ignore_ext, forbid_entities, forbid_external, forbid_dtd) 
    1086   parser._parser = None 
    1087   print traceback.format_exc() 
-> 1088   raise e 
    1089 
    1090  return t 

SAXParseException: <unknown>:1:0: no element found 

我試圖減少數據使用過濾器返回的金額,但它也沒有工作。

res = client.customerCustomerList(sid,{ 
      'group_id':'1', 
      'store_id':'1' 
     }) 

customerCustomerList()位於WSDL中,因此它可能不是權限問題。

我目前的解決辦法是枚舉customerIDs並獲取他們一個接一個,這是很不理想......

print 'Listing all the customers...' 
for i in xrange(0,999999): 
    try: 
     res = client.customerCustomerInfo(sid,str(i)) 
     print res 
    except Exception ,ex: 
     sys.stderr.write(str(ex)+'\n') 
+0

此端點似乎僅在V2 SOAP(http://www.magentocommerce.com/api/soap/customer /customer.list.html)你的'WSDL_ADDR'是什麼? – Niloct 2014-11-04 00:07:47

+0

@Niloct WSDL_ADDR是http://www.gluestore.com.au/index.php/api/v2_soap/?wsdl=1,我很確定端點在WSDL – 2014-11-04 00:13:04

+0

好的,而且Magento的版本是? – Niloct 2014-11-04 00:16:16

回答

0

無論如何,我得到的代碼通過應用過濾器工作在獲取記錄的子集一次。 Magento API確實應該提供分頁。

它不會使用SOAPpy工作,反正代碼工作使用suds

from datetime import datetime,timedelta 
from suds.client import Client 

client = Client(MAGENTO_WSDL_ADDRESS) 
sid = client.service.login(username=USER_NAME, apiKey=API_KEY) 

# Fetch all new users in last 24 hours 
filter = { 
    "complex_filter":{ 
     "item":{ 
      "key":"created_at", 
      "value":{ 
       "key":"from", 
       "value": datetime.strftime(datetime.now() - timedelta(hours=24), "%Y-%m-%d %H:%M:%S") 
      } 
     } 
    } 
} 

res = client.services.customerCustomerList(sid, filters=filter) 

# New customer ids from last 24 hours. 
new_uids = [x.customer_id for x in res] 
0

「的SAXParseException:1:0:沒有的元素中找到」問題意味着什麼服務器返回一些答案,但不是以XML格式。

相反的:

res = client.customerCustomerList(sid) 

試試這個:

res = client.customerCustomerList(sid, None) 

或本:

complex_filter = [{'complex_filter': [{ 
    'key': 'customer_id', 
    'value': [{ 
     'key': 'gt', 
     'value': 0}] 
    }] 
}] 
res = client.customerCustomerList(sid, complex_filter)