Python Suds Soap客户端错误

问题描述:

我正尝试使用Python/SUDS连接到Web服务。Python Suds Soap客户端错误

我在单个文件中有以下代码,并且我能够成功连接并收到响应。

class Suds_Connect: 
    def __init__(self, url, q_user, q_passwd): 

     logging.basicConfig(level=logging.INFO) 
     logging.getLogger('suds.client').setLevel(logging.DEBUG) 
     try: 
      # fix broken wsdl 
      # add <s:import namespace="http://www.w3.org/2001/XMLSchema"/> to the wsdl 
      imp = Import('http://www.w3.org/2001/XMLSchema', 
      location='http://www.w3.org/2001/XMLSchema.xsd') 

      wsdl_url = url 
      self.client = Client(wsdl_url, doctor=ImportDoctor(imp)) 
      t = HttpAuthenticated() 


      security = Security() 
      token = UsernameToken(q_user,q_passwd) 
      security.tokens.append(token) 
      self.client.set_options(wsse=security) 



     except Exception, e: 
      print "Unexpected error:", sys.exc_info()[0] 
      print str(e) 
      sys.exit() 


def CallWebMethod(): 

     try: 
     print ' SUDS Client' 
      print self.client 
      Person= self.client.factory.create('ns0:Person') 


      Person.name= 'bob' 
      Person.age= '34' 
      Person.address= '44, river lane' 
      print self.client.service.AddPerson(Person) 

     except WebFault, f: 
      print str(f.fault) 
     except Exception, e: 
      print str(e) 

if __name__ == '__main__': 
    errors = 0 
    sudsClient = Suds_Connect('url','user','password') 
    sudsClient.CallWebMethod() 
    print '\nFinished:' 

我想在将从按钮单击事件中调用的Python客户端应用程序中使用此代码。 我试图实现这一点,我可以打印出客户端,但是当我拨打网络服务电话(print self.client.service.AddPerson(Person))时,出现以下错误。

unsupported operand type(s) for +: 'NoneType' and 'str' 

我该如何解决这个错误?

看起来像webservice调用返回无。需要额外的信息来确定哪里出了问题。

首先 - 在调用Suds_Connect之前通过添加来启用泡沫记录。这应该为您提供有关泡沫下发生了什么的信息。

import logging 
logging.basicConfig(level=logging.DEBUG) 

另一件事是尝试获得更多的调试信息 - 请尽量不要使用以下的print self.client.service.AddPerson(Person)

result = self.client.service.AddPerson(Person) 
print str(result) 

而且这将有助于获得完整的堆栈跟踪异常 - 这行它发生在和什么是调用堆栈。请尝试注释掉except Exception, e:案例的异常处理,并在这里发布您将得到的异常。

好吧,

这似乎是我遇到的问题涉及肥皂头一代。 在SUDS中有一个包含函数xml()的文件wsse.py。

def xml(self): 
     """ 
     Get xml representation of the object. 
     @return: The root node. 
     @rtype: L{Element} 
     """ 
    root = Element('UsernameToken', ns=wssens) 
    u = Element('Username', ns=wssens) 
    u.setText(self.username) 
    root.append(u) 
    p = Element('Password', ns=wssens) 
    p.set('Type', "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest") 

    import sha 
    import base64 
    p.setText(base64.encodestring(sha.new(self.nonce + str(UTC(self.created)) + self.password).digest()).replace("\n", '')) 

    root.append(p) 
    if self.nonce is not None: 
     n = Element('Nonce', ns=wssens) 
     n.setText(base64.encodestring(self.nonce).replace("\n",'')) 
     root.append(n) 
    if self.created is not None: 
     n = Element('Created', ns=wsuns) 
     n.setText(str(UTC(self.created))) 
     root.append(n) 
    return root 

我得到了一个错误@以下行:

p.setText(base64.encodestring(sha.new(self.nonce + str(UTC(self.created)) + self.password).digest()).replace("\n", '')) 

所以我评论了这条线,并添加以下行:

p.setText(self.password) 

请注意,我在打电话over https

关于

Noel