Python suds error “'NoneType' object has no attribute 'promotePrefixes'”

允我心安 提交于 2019-12-11 10:38:45

问题


I have an ASP.NET webservice running on a Windows 7 box. I have two Linux boxes (Ubuntu 12.04) that I'm trying to hit the webservice from, using Python 2.7.3 and Suds 0.4. The script I'm trying to execute is as follows:

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()

On one of my Linux boxes, this code executes perfectly and resp will contain the expected data returned from the web service. On the other Linux box, I get the following error message:

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'

I need some ideas on what settings, etc. could be causing this difference in behavior between the two machines. Thanks in advance!


回答1:


I added lines to output additional logging information, and found that the problem had nothing to do with the Python error being thrown, but was instead due to the web service rejecting my connection. Here are the lines I added to the script posted in the question:

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

With these lines added, my script then produced the following output (partial):

<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>

From here I shifted my focus from the clients to the server, and was able to quickly identify the problem (which has nothing to do with my original question!).



来源:https://stackoverflow.com/questions/26473513/python-suds-error-nonetype-object-has-no-attribute-promoteprefixes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!