#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请求的更多相关文章

  1. 重载的方式写Python的post请求

    #encoding=utf-8#__author__="Lanyangyang" import unittestimport requestsimport json # This ...

  2. 以正确的方式开源 Python 项目

    以正确的方式开源 Python 项目 大多数Python开发者至少都写过一个像工具.脚本.库或框架等对其他人也有用的工具.我写这篇文章的目的是让现有Python代码的开源过程尽可能清 晰和无痛.我不是 ...

  3. fake-useragent,python爬虫伪装请求头

    在编写爬虫进行网页数据的时候,大多数情况下,需要在请求是增加请求头,下面介绍一个python下非常好用的伪装请求头的库:fake-useragent,具体使用说明如下: 1.在scrapy中的使用 第 ...

  4. 你必须学写 Python 装饰器的五个理由

    你必须学写Python装饰器的五个理由 ----装饰器能对你所写的代码产生极大的正面作用 作者:Aaron Maxwell,2016年5月5日 Python装饰器是很容易使用的.任何一个会写Pytho ...

  5. python学习 —— post请求方法的应用

    声明:本篇仅基于兴趣以及技术研究而对B站曾经发生过的抢楼事件背后相关技术原理进行研究而写.请不要将其作为私利而对B站以及B站用户体验造成影响!谢谢合作!若本文对B站及其用户带来困扰,请联系本人删除本文 ...

  6. 使用C/C++写Python模块

    最近看开源项目时学习了一下用C/C++写python模块,顺便把学习进行一下总结,废话少说直接开始: 环境:windows.python2.78.VS2010或MingW 1 创建VC工程 (1) 打 ...

  7. C#类的继承,方法的重载和覆写

    在网易云课堂上看到唐大仕老师讲解的关于类的继承.方法的重载和覆写的一段代码,注释比较详细,在此记下以加深理解. 小总结: 1.类的继承:允许的实例化方式:Student t=new Student() ...

  8. Python中http请求方法库汇总

    最近在使用python做接口测试,发现python中http请求方法有许多种,今天抽点时间把相关内容整理,分享给大家,具体内容如下所示: 一.python自带库----urllib2 python自带 ...

  9. 在html中写python代码的语法和特点-----基于webpy的httpserver

    在html文件里写python语法的内容,的注意事项: 1:python程序中的变量通过以下方法传入到html: 1:通过全局变量 :全局变量是不须要用$def with语法实现传递的,仅仅要定义了 ...

随机推荐

  1. Python 编程快速上手 第十四章 处理 CSV 文件和 JSON 数据

    前言 这一章分为两个部分,处理 CSV 格式的数据和处理 JSON 格式个数据. 处理 CSV 理解 csv csv 的每一行代表了电子表格中的每一行,每个逗号分开两个单元格csv 的内容全部为文本, ...

  2. 细胞迁移 | cell migration

    一些基本概念: intracellular biochemical signaling pathways:胞内生化信号通路 extracellular mechanical cues: 胞外机械信号 ...

  3. ListView的简单使用--Android

    1.本例实现效果图 2.主要是activity_main.xml(布局文件)和Activity类文件,实现过程比较简单,直接附源码了哈! activity_main.xml: <?xml ver ...

  4. 集合 (set)

    set 是一个无序不重复的元素集,集合跟字典是无序的,不支持索引 创建集合: 第一种方式:通过{ }创建 >>> num={1,2,3,4,3,3,1} >>> n ...

  5. eth

    今天说下Centos的eth0:0这个虚拟端口,应为学到ifcofig eth0:0 IP,可以给一个网卡设置俩个IP地址,但是只是临时设置,然而我想永久设置,所以就在网找,最终找到的方法是 可以先复 ...

  6. 【洛谷p1258】小车问题

    (……吓人,心有余悸) 小车问题[传送门] 洛谷算法标签:: (行吧它居然是个二分[解方程的我抖抖发瑟]) 作为一个写了一页演草纸才解出来的方程,显然我要好好写一写(希望不会半途而废) 思路: 先把其 ...

  7. sqlite3 新增数据

    cx = sqlite3.connect("c:/数据库名字")#打开数据库cu = cx.cursor()cu.execute("INSERT INTO [user] ...

  8. iphone手机在网页返回上一页时,部分字体变大问题

    最近做一个项目是,发现了一个iphone的兼容性问题,在返回上一页后,部分字体会变大,刷新就会正常. 经过总结,发现都是span标签里面的字体变大.经过查询发现,需要给span添加一个属性:displ ...

  9. MongoDB 教程(五):连接、新建数据库、删除数据库

    连接 启动 MongoDB 服务 只需要在 MongoDB 安装目录的 bin 目录下执行 mongodb 即可. 执行启动操作后,mongodb 在输出一些必要信息后不会输出任何信息,之后就等待连接 ...

  10. 【Linux】shell学习之sed

    sed替换命令 使用该命令,可以将特定字符串或匹配的规则表达式用另一个字符串替换. sed 's/88/--/' filename 将filename每行第一次出现的88用字符串--替换,然后将该文件 ...