current position:Home>Interface request processing of Python webservice
Interface request processing of Python webservice
2022-05-15 02:37:28【Koki 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 = "http://127.0.0.1:8081/PosMerchant/ZfMposPort"
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 :
print(client)
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="http://schemas.xmlsoap.org/soap/envelope/" xmlns:mpos="http://mpos.zf/">'\
'<soapenv:Header/>'\
'<soapenv:Body>'\
'<mpos:withdrawCash>'\
'<arg0>'+str(t['merCode'])+'</arg0>'\
'<arg1>'+str(t['tranAmt'])+'</arg1>'\
'<arg2>'+str(t['md5Str'])+'</arg2>'\
'<arg3>'+str(t['termID'])+'</arg3>'\
'<arg4>'+str(t['termCode'])+'</arg4>'\
'<arg5>'+str(t['settDate'])+'</arg5>'\
'</mpos:withdrawCash>'\
'</soapenv:Body>'\
'</soapenv:Envelope>'
5) How to pass parameter values : Pass values in a dictionary
t={
"channel_id":2,"ip":"129.45.6.7","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
print(result)
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 = 'http://120.24.235.105:9010/sms-service-war-1.0/ws/smsFacade.ws?wsdl'
data = {
'client_ip': '192.168.10.66', '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):
self.client=Client(url)
def get_methods_name(self):
method_list = []
for i in self.client.wsdl.services[0].ports[0].methods:
method_list.append(i)
return method_list
# Get the parameters of the method
def get_method_parm(self,method_name):
method=self.client.wsdl.services[0].ports[0].methods[method_name]
input_parames=method.binding.input
params=input_parames.param_defs(method)[0]
return params[1].name,params[1].type[0]
def run_main(self):
for method in self.get_methods_name():
func=getattr(self.client.service,method)
print(func('221.112.223.1'))
if __name__ == '__main__':
url = 'http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx?wsdl'
web=Webservice_Test(url)
# name=web.get_methods_name()[0]
# print(web.get_method_parm(name))
print(web.run_main())
copyright notice
author[Koki can test a rookie],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/132/202205120517585527.html
The sidebar is recommended
- 【python】UI/ function code seperated(ISP), TCP server receive multi client and send to a client
- Python introduction notes-1 syntax rules
- Python getting started notes - 3 common built-in functions in Python
- Python -- K-means clustering algorithm
- Python getting started notes - 4 Python operators
- Windows Python 3 installation & environment variable configuration
- Difference between Python multithreading start () and run () methods (turn)
- Install the corresponding packages for multiple versions of Python
- Python finds the corresponding substance according to the conditions and records it
- Python application scenarios and market demand
guess what you like
Python experience lesson Chapter 1 01print function
Python experience lesson Chapter 1 02 data types
Python experience lesson Chapter 1 03 conditional judgment
Python code writing specification and basic usage
Summary of Python file reading and writing methods for data analysis (open | CSV | dataframe | openpyxl)
Python data calculation method for data analysis part I (math|numpy)
Accelerating parallel computing based on python (BL) 136
[Python @ Little Turtle online class] P8 string (1) slicing & palindromes & changing the case of string & aligning the left, middle and right of string
[Python @ Little Turtle online class] P8 string (3) judgment
[Python @ Little Turtle online course] P8 string (2) find and replace
Random recommended
- Common modules and third-party libraries of Python notes in class
- Educoder Linux and Python Programming 2021 (basic syntax of classes) - level 2: properties and instantiation of classes
- Educoder Linux and Python Programming 2021 (basic syntax of classes) - level 1: Declaration and definition of classes
- Educoder Linux and Python Programming 2021 (basic syntax of classes) - Level 3: binding and method calling
- Educoder Linux and Python Programming 2021 (basic syntax of classes) - level 4: static methods and class methods
- Educoder Linux and Python Programming 2021 (basic syntax of classes) - level 5: class import
- Python: unable to connect because the target computer actively refused
- If I can only choose one of the python introductory books on the market for you, I will choose this one
- Python simulation | how to manipulate the winning or losing of football matches
- How to learn after joining our Python zero foundation learning group?
- Why choose Python as a programming language
- Functions in Python
- Python version of the lone brave | drawing + playing + Music Visualization
- Smplify -python2. seven
- Python office automation: use Python to automatically insert signatures into docx files
- Python uses the opencv method to automatically insert the signed image into any position of the image
- Python automatically inserts signatures into PDF files (pypdf2)
- Basic learning notes of Python
- Numpy, pandas, Matplotlib learning
- [brush question Python] the problem of cutting and selling pipes to maximize profits
- [Python] gradient descent method to solve the trough of univariate quadratic function
- Python regular expression
- [Python GUI] wxPython automated data generator practice
- Python script compilation process
- [Python faiss library] (I) Introduction
- Python moves (copies) the pictures (files) under one file to another folder
- Python crawling 51job position information (regular violence matching)
- Python Post Bar irrigation script
- Python simulation QR code login Baidu
- Python calls wechat to send message call through COM port
- Analysis of birthday paradox in Python
- Equal scale compression of image files in Python
- Python dynamic programming (knapsack problem and longest common substring)
- Introduction to Python Programming and data analysis (I) basic use of built-in functions
- Introduction to Python Programming and data analysis (II) basic use of list derivation
- Introduction to Python Programming and data analysis (III) basic use of branch and process control
- Python turtle painting Chinese characters
- [a quick introduction and comparison of multiple languages -- JavaScript, typescript, python, golang, trust, Java, ruby]
- Relevant knowledge of Python web development (I)
- python3. Understanding of ID function in 6