python用suds 调用webservice方法的时候报错。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python用suds 调用webservice方法的时候报错。相关的知识,希望对你有一定的参考价值。

from suds.client import Client
from suds.transport.https import HttpAuthenticated

def main():
url = '此处省略/ConfWebServiceInterface.wsdl'
client = Client(url,faults=False)
#print client
result = client.service.DelBlackList(1117,1133)
print result

if __name__=="__main__":
main()

client获取没有问题。一般这种错误是什么错误,我用这个调过公共webservice没有问题,我想是不是这个webservice有什么不一样有什么或者是区分什么东西,求懂的大神!

报错:
Traceback (most recent call last):
File "E:\py\soap1.py", line 15, in <module>
main()
File "E:\py\soap1.py", line 11, in main
result = client.service.DelBlackList(1117,1133)
File "build\bdist.win-amd64\egg\suds\client.py", line 538, in __call__
return client.invoke(args, kwargs)
File "build\bdist.win-amd64\egg\suds\client.py", line 602, in invoke
result = self.send(soapenv)
File "build\bdist.win-amd64\egg\suds\client.py", line 643, in send
result = self.succeeded(binding, reply.message)
File "build\bdist.win-amd64\egg\suds\client.py", line 678, in succeeded
reply, result = binding.get_reply(self.method, reply)
File "build\bdist.win-amd64\egg\suds\bindings\binding.py", line 145, in get_reply
replyroot = sax.parse(string=reply)
File "build\bdist.win-amd64\egg\suds\sax\parser.py", line 136, in parse
sax.parse(source)
File "E:\python\lib\xml\sax\expatreader.py", line 110, in parse
xmlreader.IncrementalParser.parse(self, source)
File "E:\python\lib\xml\sax\xmlreader.py", line 123, in parse
self.feed(buffer)
File "E:\python\lib\xml\sax\expatreader.py", line 217, in feed
self._err_handler.fatalError(exc)
File "E:\python\lib\xml\sax\handler.py", line 38, in fatalError
raise exception
SAXParseException: <unknown>:1:0: syntax error

参考技术A 其实用Python进行webservice通信进行数据交换,就是拼接字符串,没必要用第三方的库。

Python调用webservice接口

python调用webservice接口,这里我们使用suds包

如果没有直接cmd命令安装subs包 

pip suds install 

安装成功会有提示成功字样。

 

------------------------------

首先导入包

先查看一下webservice提供哪些类型及方法,之后我们才知道怎么调用,传哪些参数。

from suds.client import Client
from suds.transport.https import HttpAuthenticated #webservice需要安全难证

t = HttpAuthenticated(username=‘RFCATUSER‘,password=‘q123456‘) #安全验证所需用户,密码
url = "http://hqxt1.sinopec.com:50000/dir/wsdl?p=sa/65bd52bd76de381daf15736a37d13ab1"
test = Client(url,transport=t)
print test

技术分享

下面开始调用传参:

#coding=utf-8

#导入包
from suds.client import Client
from suds.transport.https import HttpAuthenticated #webservice需要安全难证

 

#安全验证,获取service服务

t = HttpAuthenticated(username=‘RFCATUSER‘,password=‘q123456‘) #安全验证所需用户,密码

url = "http://hqxt1.sinopec.com:50000/dir/wsdl?p=sa/65bd52bd76de381daf15736a37d13ab1"
test = Client(url,transport=t)
print test

 

#用test.factory.create创建实例

request=test.factory.create(‘DT_IPM_SEND_PSBUDGET_REQ‘)

IPM_MSG_HEAD = test.factory.create(‘MSG_HEAD‘)

request.IS_MSG_HEAD = IPM_MSG_HEAD

IPM_MSG_HEAD.SENDTIME = ‘20170421102908‘
IPM_MSG_HEAD.RECIVER = ‘ECC‘
IPM_MSG_HEAD.SENDER = ‘IPM‘
IPM_MSG_HEAD.INTERFACE_ID = ‘PROJECT_CREATE‘
IPM_MSG_HEAD.SPRAS = None
IPM_MSG_HEAD.OPERATOR = None
IPM_MSG_HEAD.SYSTEM_ID = None
IPM_MSG_HEAD.PROXY_ID = None
IPM_MSG_HEAD.GUID = None
IPM_MSG_HEAD.MANDT = None
request.IV_BUKRS = "X060"
request.IV_TESTRUN = "X"

request.IT_PSBUDGET=[]

#用test.service.XXXXX去调用方法
m=test.service.SI_IPM_SEND_PSBUDGET_REQ_A_OUT(request)
print IPM_MSG_HEAD
print request

  

 

 

 

以上是关于python用suds 调用webservice方法的时候报错。的主要内容,如果未能解决你的问题,请参考以下文章

python 怎么调用webservice ?

suds调用webservice

Python调用webservice接口

python读取webservice

suds调用webserive时出现suds.TypeNotFound错误

第七篇:suds.TypeNotFound: Type not found: '(string, http://schemas.xmlsoap.org/soap/encoding/, )