How webservice interface to the type of treatment? Suds class module using a package

JSON Import 
from suds.client Import Client


class HandleWebservice:
'' '
defines a webservice interface processing type of class
'' '
DEF the __init __ (Self, send_msg_url, api_name):
' ''
constructor
: param send_msg_url: Interface Address
: param api_name: Interface name
'' '
self.api_name = api_name
self.client = Client (send_msg_url)

DEF api_res (Self, data):
' ''
request processing method
: param data: type of dictionary data request body
: return: json data format type str
'' '
the try:
# stepped on a pit, where a one-time conversion directly if in place, because then the order of execution, will first incoming data
# 错误的处理办法:res = eval(f"self.client.service.{self.api_name}({data})")
res = f"self.client.service.{self.api_name}(data)"
res = eval(res)
res_str = json.dumps(dict(res))
return res_str
except Exception as e:
res = e
res_str = json.dumps(dict(res.fault), ensure_ascii=False)
return res_str

Guess you like

Origin www.cnblogs.com/xiaogongjin/p/11407453.html