Python SUDS错误 - SAXParseException

5

有人知道在python suds调用中为什么会出现"<unknown>:1:0: syntax error"错误,即使响应看起来像这样?

<?xml version='1.0' encoding='UTF-8'?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
  <env:Body>
    <external.bz1:reply xmlns:abn.types="uri:abn.types.asic.gov.au" xmlns:bn.types="uri:bn.types.asic.gov.au" xmlns:business.document.header.types="uri:business.document.header.types.asic.gov.au" xmlns:external.bz1="uri:external.bz1.asic.gov.au" xmlns:fss.types="uri:fss.types.asic.gov.au" xmlns:types="uri:types.asic.gov.au">
      <business.document.header.types:businessDocumentHeader>
        <business.document.header.types:messageType>bnLodgeApplication</business.document.header.types:messageType>
        <business.document.header.types:messageReferenceNumber>1</business.document.header.types:messageReferenceNumber>
        <business.document.header.types:messageVersion>1</business.document.header.types:messageVersion>
        <business.document.header.types:senderId>ASIC</business.document.header.types:senderId>
        <business.document.header.types:senderType>GOVT</business.document.header.types:senderType>
        <business.document.header.types:messageEvents>
          <business.document.header.types:messageEvent>
            <business.document.header.types:errorCode>00007</business.document.header.types:errorCode>
            <business.document.header.types:serverityCode>Error</business.document.header.types:serverityCode>
            <business.document.header.types:description>Message previously processed but no valid reponse is available</business.document.header.types:description>
          </business.document.header.types:messageEvent>
        </business.document.header.types:messageEvents>
      </business.document.header.types:businessDocumentHeader>
    </external.bz1:reply>
  </env:Body>
</env:Envelope>

这是堆栈跟踪:

Traceback:
File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "/django_projects/ecr/businessNames/views.py" in externalBz1
  19.     result = doExternalBz1(test)
File "/django_projects/ecr/businessNames/models.py" in doExternalBz1
  75.     result = client.service.externalBz1(header, body)
File "/usr/local/lib/python2.6/dist-packages/suds-0.4-py2.6.egg/suds/client.py" in __call__
  542.             return client.invoke(args, kwargs)
File "/usr/local/lib/python2.6/dist-packages/suds-0.4-py2.6.egg/suds/client.py" in invoke
  602.         result = self.send(soapenv)
File "/usr/local/lib/python2.6/dist-packages/suds-0.4-py2.6.egg/suds/client.py" in send
  643.                 result = self.succeeded(binding, reply.message)
File "/usr/local/lib/python2.6/dist-packages/suds-0.4-py2.6.egg/suds/client.py" in succeeded
  678.             reply, result = binding.get_reply(self.method, reply)
File "/usr/local/lib/python2.6/dist-packages/suds-0.4-py2.6.egg/suds/bindings/binding.py" in get_reply
  145.         replyroot = sax.parse(string=reply)
File "/usr/local/lib/python2.6/dist-packages/suds-0.4-py2.6.egg/suds/sax/parser.py" in parse
  136.             sax.parse(source)
File "/usr/lib/python2.6/xml/sax/expatreader.py" in parse
  107.         xmlreader.IncrementalParser.parse(self, source)
File "/usr/lib/python2.6/xml/sax/xmlreader.py" in parse
  123.             self.feed(buffer)
File "/usr/lib/python2.6/xml/sax/expatreader.py" in feed
  211.             self._err_handler.fatalError(exc)
File "/usr/lib/python2.6/xml/sax/handler.py" in fatalError
  38.         raise exception

Exception Type: SAXParseException at /businessNames/externalBz1/1/
Exception Value: <unknown>:1:0: syntax error

这是直接从日志中提取的,没有提到解析错误 :(

有什么想法吗?

谢谢, Ben


XML 明显是有效的。你确定它是 SAXParseException 吗?发布显示此内容的堆栈跟踪。 - Jim Garrison
我唯一的建议是传递给解析器的内容可能不完全符合您发布的内容。缓冲区开头的额外空格可能会导致此问题。 - Jim Garrison
我完全不知道该怎么办... 我粘贴的是在日志文件中显示的接收到的内容。有没有办法在解析之前删除响应中的额外空格? - Ben Kilah
你能在调试器中运行代码以验证缓冲区内容吗? - Jim Garrison
1个回答

4

我不是直接传递结果,而是采取了以下措施,这样就消除了错误。

sax = suds.sax.parser.Parser()

s_received = str(client.last_received())   # passed "client.last_received()", no error 

s_parse = sax.parse(string=s_received)

而不是像这样:

x_request = eval(client.service.ListTestAccounts)

result = x_request("1")

sax = suds.sax.parser.Parser()

s_result = str(result)           # passed "result", generated error

s_parse = sax.parse(string=s_result)

希望这有所帮助。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接