XML : Python SAX Syntax Error [suds]

I'm using suds SOAP library to try and hook into an API for a web app, and for some reason I keep getting a Syntax error. The strange thing is it gives me a success response, does the work, then gives a fatal error instead of iterating the next item in my dictionary. If I run it again, it will pass over the 1st item (gives a failed response) then does the same thing on the next item.

The following snippet of code is where the error occurs:

  def create_theme(themeDict):  for key, val in themeDict.iteritems():      client = Client(url, username=USERNAME, password=PASSWORD, faults = False)      theme = client.factory.create('theme')      theme.names.name = themeDict[key]['Theme Name']      theme.parentId = themeDict[key]['Parent Theme']      theme.description = themeDict[key]['Description']      theme.mediaGuid = themeDict[key]['Media ID']      theme.modules.module = [themeDict[key]["Module One"], themeDict[key]["Module Two"],                              themeDict[key]["Module Three"], themeDict[key]["Module Four"],                              themeDict[key]['Module Five'], themeDict[key]['Module Six']]      theme.organizationalAccess.divisionId = [themeDict[key]['Org Unit 1'], themeDict[key]['Org Unit 2'],                                                themeDict[key]['Org Unit 3'], themeDict[key]['Org Unit 4'],                                               themeDict[key]['Org Unit 5'], themeDict[key]['Org Unit 6'],                                               themeDict[key]['Org Unit 7'], themeDict[key]['Org Unit 8'],                                               themeDict[key]['Org Unit 9'], themeDict[key]['Org Unit 10']]      client.set_options(plugins=[injectAttribute()])      client.service.createTheme(theme)    

Here is the Complex Argument from the WSDL (only the field "name" is compulsory, the others are all optional)

  (theme){     id = None     parentId = None     names =         (names){           name[] = <empty>        }     order =         (order){           position[] = <empty>        }     subThemesOrder =         (subThemesOrder){           order[] = <empty>        }     description = None     mediaGuid = None     mediaVersion = None     modules =         (modules){           module[] = <empty>        }     userAccess =         (userAccess){           userId[] = <empty>        }     organizationalAccess =         (organizationalAccess){           divisionId[] = <empty>        }     themes =         (themes){           theme[] = <empty>        }   }  

You can see the SOAP request below:

  DEBUG:suds.client:sending to (https://uk-  demo.brandmaker.com/webservices/Theme/)  message:  <?xml version="1.0" encoding="UTF-8"?>  <SOAP-ENV:Envelope xmlns:ns0="http://brandmaker.com/webservices/Theme/" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">     <SOAP-ENV:Header/>     <ns1:Body>        <ns0:createTheme>           <ns0:theme>              <names>                 <name>Theme Test True</name>              </names>              <description>Test of themes</description>              <modules>                 <module>true</module>                 <module>true</module>                 <module>false</module>                 <module>true</module>                 <module>false</module>                 <module>true</module>              </modules>              <organizationalAccess>                 <divisionId>11</divisionId>                 <divisionId>7</divisionId>                 <divisionId>1</divisionId>                 <divisionId>0</divisionId>                 <divisionId>0</divisionId>                 <divisionId>0</divisionId>                 <divisionId>0</divisionId>                 <divisionId>0</divisionId>                 <divisionId>0</divisionId>                 <divisionId>0</divisionId>              </organizationalAccess>           </ns0:theme>        </ns0:createTheme>     </ns1:Body>  </SOAP-ENV:Envelope>  

And the response below (including traceback)

  `DEBUG:suds.client:headers = {'SOAPAction': u'"createTheme"', 'Content-Type': 'text/xml; charset=utf-8'}  DEBUG:suds.client:http succeeded:  --uuid:4e1182be-2973-42a8-b791-f0723e192b5d  Content-Type: application/xop+xml; charset=UTF-8; type="text/xml"  Content-Transfer-Encoding: binary  Content-ID: <root.message@cxf.apache.org>  <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"/><soap:Body><ns2:createThemeResponse xmlns:ns2="http://brandmaker.com/webservices/Theme/"><ns2:result><result>true</result><id>174</id></ns2:result></ns2:createThemeResponse></soap:Body></soap:Envelope>  --uuid:4e1182be-2973-42a8-b791-f0723e192b5d--  Traceback (most recent call last):    File "\\globm-srv01.marketing-logic.local\homedrives$\cameron.stradeski\Documents\Projects\Tools\Theme_Tree.py", line 92, in <module>      create_theme(themeDict)    File "\\globm-srv01.marketing-logic.local\homedrives$\cameron.stradeski\Documents\Projects\Tools\Theme_Tree.py", line 74, in <module>      client.service.createTheme(theme)    File "C:\Program Files\Python 2.7\Lib\suds\client.py", line 540, in __call__      return client.invoke(args, kwargs)    File "C:\Program Files\Python 2.7\Lib\suds\client.py", line 602, in invoke      result = self.send(soapenv)    File "C:\Program Files\Python 2.7\Lib\suds\client.py", line 649, in send      result = self.succeeded(binding, reply.message)    File "C:\Program Files\Python 2.7\Lib\suds\client.py", line 678, in succeeded      reply, result = binding.get_reply(self.method, reply)    File "C:\Program Files\Python 2.7\Lib\suds\bindings\binding.py", line 145, in get_reply      replyroot = sax.parse(string=reply)    File "C:\Program Files\Python 2.7\Lib\suds\sax\parser.py", line 136, in parse      sax.parse(source)    File "C:\Program Files\Python 2.7\Lib\xml\sax\expatreader.py", line 107, in parse      xmlreader.IncrementalParser.parse(self, source)    File "C:\Program Files\Python 2.7\Lib\xml\sax\xmlreader.py", line 123, in parse      self.feed(buffer)    File "C:\Program Files\Python 2.7\Lib\xml\sax\expatreader.py", line 214, in feed      self._err_handler.fatalError(exc)    File "C:\Program Files\Python 2.7\Lib\xml\sax\handler.py", line 38, in fatalError      raise exception  xml.sax._exceptions.SAXParseException: <unknown>:1:0: syntax error`  

If any more information is required, please let me know.

No comments:

Post a Comment