使用python的 Requests模块实现简单的接口自动化

1.安装Requests;

   pip  install requests

2.在HTTP的请求中,最常使用的分别有GET,POST,通过request库也是可以实现,下面用post方法做接口测试

#!/usr/bin/env python
#coding:utf-8

import requests
#传入参数
url = 'http://ip.taobao.com/service/getIpInfo.php'
param = [{"ip": "117.89.35.58"}, {"ip": "117.79.35.58"}, {"ip": "117.69.35.58"}]
def ta_bao(url,param):
    result=requests.post(url,param)#调用requests的post方法
    print (result.json())#打印返回结果
for item in param:#通过for循环插入参数
 ta_bao(url,item)

 执行以下就会打印出接口返回结果

猜你喜欢

转载自www.cnblogs.com/cc233/p/10956232.html