current position:Home>Interface request processing of Python webservice

Interface request processing of Python webservice

2022-05-15 02:37:28Koki can test a rookie

1) introduce suds library , The code is as follows :

from suds.client import Client

2) Create a webservice object , To call webservice Various interfaces inside

webservice Access address

user_url = ""
client = Client(user_url)  # Client There are direct access URL, Can generate a  webservice  object 

3) Print this out wsdl All interface information in the address :# Print out webservice The names of all interface methods inside , The result is shown in the screenshot below :


4) utilize soapui( Software tools ) Let's see webservice Composition and parameters of an interface , One of the registered interfaces , As shown below :

'<soapenv:Envelope xmlns:soapenv="" xmlns:mpos="http://mpos.zf/">'\

5) How to pass parameter values : Pass values in a dictionary

    "channel_id":2,"ip":"","mobile":'mobile' ,"pwd":"123456","user_id" :"shabicu8","verify_code":'123456'}

6) How to be in Python To register this interface service :

client This object , call service This method , Then call userRegister This interface function , Pass the parameter dictionary we just prepared in the function t

result = client.service.userRegister(body)

Print return results


7) The final return result is printed as follows :

(result){retCode=‘0’,retInfo = ‘ok’}

Two 、 Write a encapsulated class .

from suds.client import Client
class WebServiceTest:
    def web_service_test(self, url, data, method):
        if method == 'sendMCode':
            res = Client(url).service.sendMCode(data)
        elif method == 'userRegister':
            res = Client(url).service.userRegister(data)
        elif method == 'verifiedUserAuth':
            res = Client(url).service.verifiedUserAuth(data)
        elif method == 'bindBankCard':
            res = Client(url).service.bindBankCard(data)
        return res

#  Create examples 
Client = WebServiceTest()

url = ''
data = {
    'client_ip': '', 'smpl_id': '1', 'mobile': '15096090551'}
res = Client.web_service_test(url, data, 'sendMCode')
print(' The result of SMS sending is :{0}'.format(res))

3、 ... and 、 Traverse all of url Inside webservice request :

from suds.client import Client

class Webservice_Test:
    def __init__(self,url):
    def get_methods_name(self):
        method_list = []
        for i in[0].ports[0].methods:
        return method_list
    # Get the parameters of the method 
    def get_method_parm(self,method_name):[0].ports[0].methods[method_name]
        return params[1].name,params[1].type[0]
    def run_main(self):
        for method in self.get_methods_name():
if __name__ == '__main__':
    url = ''
    # name=web.get_methods_name()[0]
    # print(web.get_method_parm(name))

copyright notice
author[Koki can test a rookie],Please bring the original link to reprint, thank you.

Random recommended