Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Parul M Newsgroups: comp.lang.python Subject: Help needed in mapping Magento 1.x/PHP data structure into Python equivalent for suds Date: Tue, 31 May 2016 22:25:57 +0530 Lines: 167 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de VC8365fiMh5Jh0oxlxhsBACbY32rwBKqAzeeNDheQhdw== Return-Path: X-Original-To: Python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'received:209.85.223': 0.03; 'subject:Python': 0.05; 'soap': 0.07; 'username,': 0.07; 'api': 0.09; 'args,': 0.09; 'prefixes': 0.09; 'subject:into': 0.09; 'subject:Help': 0.10; 'python': 0.10; 'syntax': 0.13; 'subject: \n ': 0.15; '1.x': 0.16; "api's": 0.16; 'instance:': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'skip:} 10': 0.16; 'obviously': 0.16; '>>>': 0.20; 'all,': 0.20; 'skip:" 40': 0.20; '"",': 0.22; 'provided,': 0.22; 'skip:$ 20': 0.22; '(most': 0.24; 'skip:b 30': 0.24; 'appreciated.': 0.27; 'message- id:@mail.gmail.com': 0.27; 'correct': 0.28; "skip:' 10": 0.28; 'invoke': 0.29; 'array': 0.29; 'raise': 0.29; 'print': 0.30; 'subject:/': 0.30; 'creating': 0.30; 'skip:a 70': 0.30; '8bit%:25': 0.33; 'raised': 0.33; 'traceback': 0.33; 'version:': 0.33; "skip:' 20": 0.34; 'structure': 0.34; 'file': 0.34; 'server': 0.34; 'skip:& 20': 0.35; 'received:google.com': 0.35; 'library.': 0.35; 'skip:" 50': 0.35; 'skip:& 60': 0.35; 'skip:i 20': 0.36; 'url:org': 0.36; 'received:209.85': 0.36; 'guidance': 0.36; 'to:addr:python-list': 0.36; 'skip:& 10': 0.37; 'client': 0.37; 'thanks': 0.37; '(2)': 0.37; 'received:209': 0.38; 'data': 0.39; 'skip:e 20': 0.39; 'to:addr:python.org': 0.40; 'url:schemas': 0.40; 'customer': 0.62; 'skip:n 10': 0.62; 'skip:a 40': 0.64; 'reply,': 0.72; '__call__': 0.84; 'calls,': 0.84; 'subject:Magento': 0.84; 'magento': 0.91; 'ports': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to; bh=aDjkbjHvgT3qfu2BYimlu1wwpbBg+J4zlaRENN2muFo=; b=hdgk4YjB8vYOkbQU3/i1jC4BP5iGiIC9l1RB8JPW44z8MZQ2cKLRBC4lc7bRD7kfm+ ZYip6xdXGjQhI3g99FILeX/b2afyUCfAGM4JOcZMiDJ+4rgVkwPEBBcOlgsiotOhAjKO F3XMzSzdpo+V0yUSqYNFJ4EXzT2PC9xMcOhq/FxgP5C0ctUpii0wfIchcXVNnv1T944p dTkgnXi6/52PUo7QcZoIjYIMugJzPr+EbWERkErXWP5tJjLKWMFfRJV8LAXHKhhx+C/k CyrCu43KfAYWPKqBOsfTFAOrpI91SD39JcJEsScwyXfrZLI4hvtfNxieEo5q0vsyJO5G XjIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to; bh=aDjkbjHvgT3qfu2BYimlu1wwpbBg+J4zlaRENN2muFo=; b=ZdNlSclSkwvJOU1G7dXHu32AXkjLOBLtRbPpLREqw2b7wWdfiXMG/Cl54b2KZQsy1i vH41Hklir0XFS5wdc+NtrYJCbwp8m0lbFa79UtGaeBz9nAAyaf2GR49ryFAhZpUyI4fn RBo5K0BujIlMo2lrDdjkq74LnIq9hdm4tD2bL6N07R9xWGqQr0UIjDu1LQGWWIPrPUGT 27fdLfUpjg9/ttYXwbVJJLWfOH5U2D4Xo1gL+22mwiaZtEXdsHu3tKgBFiBCl5eV9Q3f tGatWYL/Xt0B73cdXu+EAEXfFzMLJnMbhMbeGXAvgf120gdtN8cntmPbPwd8NHzcz58Q 5t3A== X-Gm-Message-State: ALyK8tJVm3IEh288I+/othpueRDdiybAdxmhAy6KQWkhwNdqANHvsrgu72HvV8FpEPycSP0fiLfHeb3kI42MZw== X-Received: by 10.107.174.93 with SMTP id x90mr10736857ioe.76.1464713757733; Tue, 31 May 2016 09:55:57 -0700 (PDT) X-Mailman-Approved-At: Wed, 01 Jun 2016 02:09:28 -0400 X-Content-Filtered-By: Mailman/MimeDel 2.1.22 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: Xref: csiph.com comp.lang.python:109303 Hello All, I need assistance in calling Magento 1.x SOAP API's using Python suds library. How to map the *PHP data structure array(array(k1=>v1, k2=>v2,.....)) in terms of python suds*??? The exposed SOAP API syntax for creating a new customer in magento: ult = $client->call($session, 'customer.create', array(array('email' => ' customer-mail@example.org', 'firstname' => 'Dough', 'lastname' => 'Deeks', 'password' => 'password', 'website_id' => 1, 'store_id' => 1))); suds client instance: >>> print client Suds ( https://fedorahosted.org/suds/ ) version: 0.4 GA build: R699-20100913 Service ( MagentoService ) tns="urn:Magento" Prefixes (2) ns0 = "http://schemas.xmlsoap.org/soap/encoding/" ns1 = "urn:Magento" Ports (1): (Port) Methods (8): call(xs:string sessionId, xs:string resourcePath, xs:anyType args, ) endSession(xs:string sessionId, ) globalFaults(xs:string sessionId, ) login(xs:string username, xs:string apiKey, ) multiCall(xs:string sessionId, FixedArray calls, xs:anyType options, ) resourceFaults(xs:string resourceName, xs:string sessionId, ) resources(xs:string sessionId, ) startSession() Types (49): ns0:Array ns0:ENTITIES ns0:ENTITY *My Efforts*: >>> params={ ... 'email':'customer123@example.org', ... 'firstname':'Dough', ... 'lastname':'Deeks', ... 'password':'password', ... 'website_id':1, ... 'store_id':1, ... 'group_id':1 ... } >>> a1=client.factory.create("ns0:Array") >>> a1["item"]=[{"key":key,"value":params[key]} for key in params] >>> a1 (Array){ _arrayType = "" _offset = "" _id = "" _href = "" item[] = { value = 1 key = "group_id" }, { value = 1 key = "store_id" }, { value = "Dough" key = "firstname" }, { value = "Deeks" key = "lastname" }, { value = 1 key = "website_id" }, { value = "password" key = "password" }, { value = "customer123@example.org" key = "email" }, } >>> a3=client.factory.create("ns0:Array") >>> a3.array=a1 >>> a3 (Array){ _arrayType = "" _offset = "" _id = "" _href = "" array = (Array){ _arrayType = "" _offset = "" _id = "" _href = "" item[] = { value = 1 key = "group_id" }, { value = 1 key = "store_id" }, { value = "Dough" key = "firstname" }, { value = "Deeks" key = "lastname" }, { value = 1 key = "website_id" }, { value = "password" key = "password" }, { value = "customer123@example.org" key = "email" }, } } >>> client.service.call(session,'customer.create',a3) Traceback (most recent call last): File "", line 1, in File "C:\Python27\lib\site-packages\suds\client.py", line 542, in __call__ return client.invoke(args, kwargs) File "C:\Python27\lib\site-packages\suds\client.py", line 602, in invoke result = self.send(soapenv) File "C:\Python27\lib\site-packages\suds\client.py", line 643, in send result = self.succeeded(binding, reply.message) File "C:\Python27\lib\site-packages\suds\client.py", line 678, in succeeded reply, result = binding.get_reply(self.method, reply) File "C:\Python27\lib\site-packages\suds\bindings\binding.py", line 151, in get_reply self.detect_fault(soapbody) File "C:\Python27\lib\site-packages\suds\bindings\binding.py", line 182, in detect_fault raise WebFault(p, fault) suds.WebFault: Server raised fault: 'Customer email is required' The data provided, is obviously not in the correct format. Any guidance would be much appreciated. Thanks