Python suds错误"' NoneType'对象没有属性' promotePrefixes'"

时间:2014-10-20 19:34:20

标签: python web-services soap ntlm suds

我在Windows 7机器上运行了一个ASP.NET Web服务。我有两个Linux盒子(Ubuntu 12.04),我试图使用Python 2.7.3和Suds 0.4来点击Web服务。我正在尝试执行的脚本如下:

from suds import client
from suds.transport.https import WindowsHttpAuthenticated
url = "https://webserver.mydomain.com/webservice/services.asmx?WSDL"
ntlm = WindowsHttpAuthenticated(username = "user", password = "pwd")
c = client.Client(url, transport = ntlm)
resp = c.service.GetData()

在我的一个Linux机器上,此代码执行完美,resp将包含从Web服务返回的预期数据。在另一个Linux框中,我收到以下错误消息:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/var/www/dev/local/lib/python2.7/site-packages/suds/client.py", line 542, in __call__
    return client.invoke(args, kwargs)
  File "/var/www/dev/local/lib/python2.7/site-packages/suds/client.py", line 602, in invoke
    result = self.send(soapenv)
  File "/var/www/dev/local/lib/python2.7/site-packages/suds/client.py", line 643, in send
    result = self.succeeded(binding, reply.message)
  File "/var/www/dev/local/lib/python2.7/site-packages/suds/client.py", line 678, in succeeded
    reply, result = binding.get_reply(self.method, reply)
  File "/var/www/dev/local/lib/python2.7/site-packages/suds/bindings/binding.py", line 149, in get_reply
    soapenv.promotePrefixes()
AttributeError: 'NoneType' object has no attribute 'promotePrefixes'

我需要一些关于什么设置等的想法可能导致两台机器之间的行为差​​异。提前谢谢!

1 个答案:

答案 0 :(得分:7)

我添加了行以输出其他日志记录信息,并发现该问题与抛出的Python错误无关,而是由于Web服务拒绝我的连接。以下是我在问题中发布的脚本中添加的行:

import logging
logging.basicConfig(level=logging.INFO)
logging.getLogger('suds.client').setLevel(logging.DEBUG)

添加这些行后,我的脚本会生成以下输出(部分):

<body>
<div id="header"><h1>Server Error</h1></div>
<div id="content">
 <div class="content-container"><fieldset>
  <h2>403 - Forbidden: Access is denied.</h2>
  <h3>You do not have permission to view this directory or page using the credentials that you supplied.</h3>
 </fieldset></div>
</div>
</body>

从这里开始,我将注意力从客户端转移到服务器上,并且能够快速识别问题(这与我原来的问题无关!)。