Skip to main content
 首页 » 编程设计

Python 泡沫错误 "' NoneType' 对象没有属性 'promotePrefixes'“

2025年05月04日13java哥

我有一个在 Windows 7 机器上运行的 ASP.NET 网络服务。我有两个 Linux 机器(Ubuntu 12.04),我试图使用 Python 2.7.3 和 Suds 0.4 从中获取网络服务。我尝试执行的脚本如下:

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' 

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

请您参考如下方法:

我添加了一些行来输出额外的日志信息,发现问题与抛出的 Python 错误无关,而是由于网络服务拒绝了我的连接。以下是我添加到问题中发布的脚本中的行:

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> 

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