0

我对 python 中的 SUDS 有一个奇怪的问题。

我正在编写一个使用 SOAP 服务的应用程序。大约 2 个月的时间里,一切都很顺利。突然间,它停止了工作。这是奇怪的部分。

如果我为我编写的 suds manager 运行 unittest,一切都会顺利进行,并且测试会像往常一样通过。如果我在 GUI 应用程序中运行代码,它会失败,并带有以下回溯:

ERROR:suds.client:<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:ns0="http://service.skip.fiskistofa.is/" 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:getLandings>
         <from>2013-10-11</from>
         <to>2013-10-01</to>
      </ns0:getLandings>
   </ns1:Body>
</SOAP-ENV:Envelope>
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 808, in __bootstrap_inner
    self.run()
  File "/home/fintor/bin/python/aflafrettir/gui/gui.py", line 332, in run
    landings = self.manager.get_landings(self.date_from, self.date_to)
  File "/home/fintor/bin/python/aflafrettir/landings/manager.py", line 66, in get_landings
    return self.call_method('getLandings', date_from, date_to)
  File "/home/fintor/bin/python/aflafrettir/landings/manager.py", line 49, in call_method
    return getattr(self.client.service, method)(*args)
  File "/home/fintor/.virtenvs/aflafrettir/lib/python2.7/site-packages/suds/client.py", line 542, in __call__
    return client.invoke(args, kwargs)
  File "/home/fintor/.virtenvs/aflafrettir/lib/python2.7/site-packages/suds/client.py", line 602, in invoke
    result = self.send(soapenv)
  File "/home/fintor/.virtenvs/aflafrettir/lib/python2.7/site-packages/suds/client.py", line 649, in send
    result = self.failed(binding, e)
  File "/home/fintor/.virtenvs/aflafrettir/lib/python2.7/site-packages/suds/client.py", line 702, in failed
    r, p = binding.get_fault(reply)
  File "/home/fintor/.virtenvs/aflafrettir/lib/python2.7/site-packages/suds/bindings/binding.py", line 265, in get_fault
    raise WebFault(p, faultroot)
WebFault: Server raised fault: 'Couldn't create SOAP message due to exception: XML reader error: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character 'C' (code 67) in prolog; expected '<'
 at [row,col {unknown-source}]: [1,1]'

失败的代码在 GUI 应用程序(PySide)中的线程中运行,相关代码在这里:

class Worker(Thread):
  signal = AflafrettirSignal()

  def __init__(self, queue, manager, date_from, date_to):
    super(Worker, self).__init__()
    self.queue = queue
    self.manager = manager
    self.date_from = date_from
    self.date_to = date_to
    self.daemon = True

  def run(self):
    landings = self.manager.get_landings(self.date_from, self.date_to)

    for l in landings:
      tmp = Landings()
      tmp.set_variable(l)
      tmp.calc_total_catch()
      self.queue.put(tmp)

    self.signal.work_done.emit(True)

它在gui中被调用,如下所示:

manager = LandingsManager()
manager.set_credentials(self.username, self.password)
manager.get_client()
worker = Worker(self.queue, manager, date_from, date_to)
worker.start()

最后,这是来自 unittest 模块的代码,它工作正常:

manager = LandingsManager()
manager.set_credentials(usern, passw)
manager.get_client()
data = manager.get_landings('2013-10-01', '2013-10-11')

我已验证设置凭据时的用户名和密码相同,以及调用 get_landings 方法的日期和日期。

就像我说的,这是一个奇怪的问题,我不确定是什么导致它在一个地方失败,而在另一个地方工作。我希望有人能就原因告诉我。

编辑:

我发现出了什么问题。密码包含一个回车,而 SOAP 服务不喜欢这样。

4

0 回答 0