Python调用webservice接口
短信预约 -IT技能 免费直播动态提醒
from suds.client import Client
url = "http://218.90.174.179:50038/JmYfjzService/clientRegisterService?WSDL"
test = Client(url)
print(test)
m=test.service.clientListen()
print(m)
python调用webservice接口,这里我们使用suds包
如果没有直接cmd命令安装subs包
pip suds install
安装成功会有提示成功字样。
------------------------------
首先导入包
先查看一下webservice提供哪些类型及方法,之后我们才知道怎么调用,传哪些参数。
1234567 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
下面开始调用传参:
123456789101112131415161718192021222324252627282930313233343536373839404142434445 #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 出错"No handlers could be found for logger 'suds.client'"
解决方法:
1、找到client.py,在安装suds的路径中
这里写图片描述
2、在client.py中添加,如下图
import logging
getLogger('suds.client').setLevel(logging.CRITICAL)
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341