设为首页 加入收藏

TOP

Python自动化--语言基础8--接口请求及封装(二)
2017-12-23 06:07:11 】 浏览:270
Tags:Python 自动化 语言基础 8-- 接口 请求 封装
7 print("json类型转化成python数据类型",json_r) 8 except BaseException as e: 9 print("请求失败!",str(e)) 10 def post(self,url,para,headers): 11 try: 12 r = requests.post(url,data=para,headers=headers) 13 print("获取返回的状态码",r.status_code) 14 json_r = r.json() 15 print("json类型转化成python数据类型",json_r) 16 except BaseException as e: 17 print("请求失败!",str(e)) 18 def post_json(self,url,para,headers): 19 try: 20 data = para 21 data = json.dumps(data) #python数据类型转化为json数据类型 22 r = requests.post(url,data=data,headers=headers) 23 print("获取返回的状态码",r.status_code) 24 json_r = r.json() 25 print("json类型转化成python数据类型",json_r) 26 except BaseException as e: 27 print("请求失败!",str(e)) 28 29 url = "http://v.juhe.cn/laohuangli/d" 30 para = {"key":"eeeeeeeeeeeeeeeeeeeeeeeeeeeeeee","date":"2017-3-22"} 31 headers ={} 32 33 q = Webrequests() 34 35 q.get(url,para,headers) 36 q.post(url,para,headers) 37 q.post_json(url,para,headers)

 

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Python连接SQL Server获取数据转J.. 下一篇Python连接SQL Server数据获取2

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目