重载的方式写Python的get请求
#encoding=utf-8
#__author__="Lanyangyang" import unittest
import requests
import json # This is a public get method.
def test_public_get(self, url, path, params): # get request method
response = requests.get(url=url + path, params=params) # Is the return status code 200?
self.assertEqual(response.status_code, 200, msg="The status code is not 200") # Is the return message SUCCESS?
response_text = requests.get(url=url + path, params=params).text # Convert response content into dictionary format.
response_dict = json.loads(response_text) # Gets the value of the response message.
response_message = response_dict['message'] #Determine the value of message.
self.assertEqual(response_message, 'SUCCESS', msg='The response message is not SUCCESS') #Print response text.
print(response.text) #Output text in JSON format
response2 = requests.get(url=url + path, params=params).json()
r = json.dumps(response2, indent=2, sort_keys=True) # Print response text in JSON format.
print("The return information is as follows:")
print(r) print("test_public_get call success.") # This is a public get method, include headers
def test_public_get(self, url, path, params,headers): # get request method
response = requests.get(url=url + path, params=params,headers=headers) # Is the return status code 200?
self.assertEqual(response.status_code, 200, msg="The status code is not 200") # Is the return message SUCCESS?
response_text = requests.get(url=url + path, params=params,headers=headers).text # Convert response content into dictionary format.
response_dict = json.loads(response_text) # Gets the value of the response message.
response_message = response_dict['message'] # Determine the value of message.
self.assertEqual(response_message, 'SUCCESS', msg='The response message is not SUCCESS') # Print response text.
print(response.text) # Output text in JSON format
response2 = requests.get(url=url + path, params=params,headers=headers).json()
r = json.dumps(response2, indent=2, sort_keys=True) # Print response text in JSON format.
print("The return information is as follows:")
print(r) print("test_public_get call success.") # This is a public get method, include headers,no param
def test_public_get(self, url, path,headers): # get request method
response = requests.get(url=url + path,headers=headers) # Is the return status code 200?
self.assertEqual(response.status_code, 200, msg="The status code is not 200") # Is the return message SUCCESS?
response_text = requests.get(url=url + path, headers=headers).text # Convert response content into dictionary format.
response_dict = json.loads(response_text) # Gets the value of the response message.
response_message = response_dict['message'] # Determine the value of message.
self.assertEqual(response_message, 'SUCCESS', msg='The response message is not SUCCESS') # Print response text.
print(response.text) # Output text in JSON format
response2 = requests.get(url=url + path,headers=headers).json()
r = json.dumps(response2, indent=2, sort_keys=True) # Print response text.
print("The return information is as follows:")
print(r) print("test_public_get call success")
重载的方式写Python的get请求的更多相关文章
- 重载的方式写Python的post请求
#encoding=utf-8#__author__="Lanyangyang" import unittestimport requestsimport json # This ...
- 以正确的方式开源 Python 项目
以正确的方式开源 Python 项目 大多数Python开发者至少都写过一个像工具.脚本.库或框架等对其他人也有用的工具.我写这篇文章的目的是让现有Python代码的开源过程尽可能清 晰和无痛.我不是 ...
- fake-useragent,python爬虫伪装请求头
在编写爬虫进行网页数据的时候,大多数情况下,需要在请求是增加请求头,下面介绍一个python下非常好用的伪装请求头的库:fake-useragent,具体使用说明如下: 1.在scrapy中的使用 第 ...
- 你必须学写 Python 装饰器的五个理由
你必须学写Python装饰器的五个理由 ----装饰器能对你所写的代码产生极大的正面作用 作者:Aaron Maxwell,2016年5月5日 Python装饰器是很容易使用的.任何一个会写Pytho ...
- python学习 —— post请求方法的应用
声明:本篇仅基于兴趣以及技术研究而对B站曾经发生过的抢楼事件背后相关技术原理进行研究而写.请不要将其作为私利而对B站以及B站用户体验造成影响!谢谢合作!若本文对B站及其用户带来困扰,请联系本人删除本文 ...
- 使用C/C++写Python模块
最近看开源项目时学习了一下用C/C++写python模块,顺便把学习进行一下总结,废话少说直接开始: 环境:windows.python2.78.VS2010或MingW 1 创建VC工程 (1) 打 ...
- C#类的继承,方法的重载和覆写
在网易云课堂上看到唐大仕老师讲解的关于类的继承.方法的重载和覆写的一段代码,注释比较详细,在此记下以加深理解. 小总结: 1.类的继承:允许的实例化方式:Student t=new Student() ...
- Python中http请求方法库汇总
最近在使用python做接口测试,发现python中http请求方法有许多种,今天抽点时间把相关内容整理,分享给大家,具体内容如下所示: 一.python自带库----urllib2 python自带 ...
- 在html中写python代码的语法和特点-----基于webpy的httpserver
在html文件里写python语法的内容,的注意事项: 1:python程序中的变量通过以下方法传入到html: 1:通过全局变量 :全局变量是不须要用$def with语法实现传递的,仅仅要定义了 ...
随机推荐
- 如何有效地使用t-SNE | How to Use t-SNE Effectively
熟练使用PCA和tSNE,彻底理解底层的原理是非常有必要的. 参考:How to Use t-SNE Effectively Real-time tSNE Visualizations with Te ...
- spring boot ----> 和mybatis。。。
环境: centos6.8,jdk1.8.0_172,maven3.5.4,spring boot1.5.15 1.使用maven命令:mvn dependency:tree查看mybatis-spr ...
- English Voice of <<See You Again >>
<See You Again >(<当我们再相见>) 演唱:Wiz Khalifa/Charlie Puth 维兹·卡利法/查理·普斯 It's been a long da ...
- Hibernate第一个程序(最基础的增删改查) --Hibernate
本例实现Hibernate的第一个程序,Hibernate的优点我想大家都很清楚,在这里不做过多赘述.总之,使用Hibernate对数据库操作,也就是来操作实体对象的! 项目目录: 一.第一步要做的就 ...
- LeetCode--014--最长公共前缀
问题描述: 编写一个函数来查找字符串数组中的最长公共前缀. 如果不存在公共前缀,返回空字符串 "". 示例 1: 输入: ["flower","flo ...
- MyEclipse6.5的反编译插件的安装
常用的几种反编译工具 1. JD-GUI[推荐] JD-GUI是属于Java Decompiler项目(JD项目)下个的图形化运行方式的反编译器.JD-Eclipse属于Java Decompiler ...
- 4.1.6 Grundy数-硬币游戏2
Problem Description: Alice 和 Bob 在玩一个游戏.给定 k 个数字 a1,a2,……,ak.一开始,有n堆硬币,每堆各有 Xi 枚硬币.Alice 和 Bob 轮流选出一 ...
- 『计算机视觉』经典RCNN_其一:从RCNN到Faster-RCNN
RCNN介绍 目标检测-RCNN系列 一文读懂Faster RCNN 一.目标检测 1.两个任务 目标检测可以拆分成两个任务:识别和定位 图像识别(classification)输入:图片输出:物体的 ...
- DVWA--XSS解题过程
XSS概念:通常指黑客通过HTML注入纂改了网页,插入恶意脚本,从而在用户浏览网页时,控制用户浏览器的一种攻击. XSS有三种: 反射型xss:只是简单地把用户输入的数据反射给浏览器,简单来说,黑客往 ...
- Web App和Native App的比较
一.Web App vs. Native App 比起手机App,网站有一些明显的优点. 跨平台:所有系统都能运行 免安装:打开浏览器,就能使用 快速部署:升级只需在服务器更新代码 超链接:可以与其他 ...