使用python suds来使用用php编写的soap webservice,会发生SAXParseException错误

时间:2013-07-25 02:02:55

标签: python suds

我使用以下代码来使用用PHP编写的soap webservice

#!/usr/local/bin/python

import logging
logging.basicConfig(levee = logging.INFO)
logging.getLogger('suds.client').setLevel(logging.DEBUG)
logging.getLogger('suds.wsdl').setLevel(logging.DEBUG)
import urllib2
from suds.client import Client
from suds.sax.element import Element


url = 'a sopa webservice url'
client = Client(url)

出现以下错误:

Traceback (most recent call last):
File "./auth.py", line 13, in <module>
   client = Client(url)
File "build/bdist.linux-x86_64/egg/suds/client.py", line 112, in __init__
File "build/bdist.linux-x86_64/egg/suds/reader.py", line 152, in open
File "build/bdist.linux-x86_64/egg/suds/wsdl.py", line 136, in __init__
File "build/bdist.linux-x86_64/egg/suds/reader.py", line 79, in open
File "build/bdist.linux-x86_64/egg/suds/reader.py", line 101, in download
File "build/bdist.linux-x86_64/egg/suds/sax/parser.py", line 136, in parse
File "/usr/local/lib/python2.7/xml/sax/expatreader.py", line 107, in parse
xmlreader.IncrementalParser.parse(self, source)
File "/usr/local/lib/python2.7/xml/sax/xmlreader.py", line 125, in parse
self.close()
File "/usr/local/lib/python2.7/xml/sax/expatreader.py", line 220, in close
self.feed("", isFinal = 1)
File "/usr/local/lib/python2.7/xml/sax/expatreader.py", line 214, in feed
self._err_handler.fatalError(exc)
File "/usr/local/lib/python2.7/xml/sax/handler.py", line 38, in fatalError
raise exception
xml.sax._exceptions.SAXParseException: <unknown>:1:0: no element found

我是suds和sopa webservice的新手,我不知道这个错误意味着什么,有人可以给我一些建议吗

2 个答案:

答案 0 :(得分:1)

您需要此行来调试:

logging.getLogger('suds.transport').setLevel(logging.DEBUG)

示例输出:

DEBUG:suds.transport.http:received:
CODE: 200
HEADERS: {'content-length': '16', ..., 'connection': 'close', 'x-sharepointhealthscore': '0', 'cache-control': 'private, max-age=0', 'date': 'Tue, 25 Mar 2014 11:24:51 GMT', 'www-authenticate': 'NTLM'}
MESSAGE:
401 UNAUTHORIZED
DEBUG:suds.client:HTTP succeeded:
401 UNAUTHORIZED
ERROR:suds.client:<suds.sax.document.Document instance at 0x02C21AF8>
Traceback (most recent call last):
  File "ExpiryMonitor.py", line 99, in <module>
    if __name__ == '__main__': main()
  File "ExpiryMonitor.py", line 66, in main
    items = c_lists.service.GetListItems(LIST_ID, VIEW_ID)
  File "build\bdist.win32\egg\suds\client.py", line 521, in __call__
  File "build\bdist.win32\egg\suds\client.py", line 581, in invoke
  File "build\bdist.win32\egg\suds\client.py", line 621, in send
  File "build\bdist.win32\egg\suds\client.py", line 661, in process_reply
  File "build\bdist.win32\egg\suds\client.py", line 832, in _parse
  File "build\bdist.win32\egg\suds\sax\parser.py", line 133, in parse
  File "C:\python27\lib\xml\sax\expatreader.py", line 107, in parse
    xmlreader.IncrementalParser.parse(self, source)
  File "C:\python27\lib\xml\sax\xmlreader.py", line 123, in parse
    self.feed(buffer)
  File "C:\python27\lib\xml\sax\expatreader.py", line 211, in feed
    self._err_handler.fatalError(exc)
  File "C:\python27\lib\xml\sax\handler.py", line 38, in fatalError
    raise exception
xml.sax._exceptions.SAXParseException: <unknown>:1:0: syntax error

显然,即使维护的suds-jurko fork在使用权限不足的登录时也不会出错。

答案 1 :(得分:0)

通常,这意味着服务器正在返回数据,但它不是有效的XML。这可能是服务器问题。