艺赛旗 RPA9.0全新首发免费下载 点击下载
http://www.i-search.com.cn/index.html?from=line1
在项目中有时候会需要调用接口数据交互来进行流程配置。这里分享一下通过全局函数调用 API 接口的代码。post,get 两种方式都做了封装。
from urllib import request
from urllib import parse
‘’’ post_responce 调用接口(post)
入参
url_path 接口URL
param_dict 参数字典
返回值
result 接口的返回结果
‘’’
def post_responce(url_path,param_dict={}):
result = ‘’
try:
postdata = parse.urlencode(param_dict).encode(‘utf-8’)
responce = request.urlopen(url_path,data = postdata)
result = responce.read().decode(‘utf-8’)
except Exception as e:
print(e)
return result
‘’’ get_responce 调用接口(get)
入参
url_path 接口URL
param_dict 参数字典
返回值
result 接口的返回结果
‘’’
def get_responce(url_path,param_dict={}):
r