#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. 管家基因 | Human housekeeping genes

    管家基因就是在细胞里稳定表达的基因,及时在胁迫状态下,表达的差异也不大. 以前做实验的时候就经常听说管家基因,因为在做RT-PCR的时候需要同时检测管家基因,这样可以用于矫正我们不同批次的结果. Li ...

  2. Spark分布式安装

    三台 服务器 n0,n2,n3 centos 6.4 X64 JDK, SCALA 2.11 Hadoop 2.2.0 spark-0.9.1-bin-hadoop2.tgz 说明: 1.所有机器上安 ...

  3. Python安装第三方库,报错超时: Read timed out.

    1.安装beautifulsoup4 >pip install beautifulsoup4 报错超时: Read timed out. 2.解决办法:pip --default-timeout ...

  4. 通过selenium控制浏览器滚动条

    目的:通过selenium控制浏览器滚动条 原理:通过 driver.execute_script()执行js代码,达到目的 driver.execute_script("window.sc ...

  5. LVM(逻辑卷管理)从0到实战

    一.请看图 二.LVM——Logical Volume Manager LVM就是动态卷管理,可以将多个硬盘和硬盘分区做成一个逻辑卷,并把这个逻辑卷作为一个整体来统一管理,动态对分区进行扩缩空间大小, ...

  6. 【MySQL】【1】表中存在重复记录,删除保留其中一条

    --删除题库(TABLE_Q )中,标题(TITLE )和类型(TYPE )都相同的数据,仅保留ID最小的一条 DELETE TABLE_Q FROM TABLE_Q, ( ) T2 WHERE TA ...

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

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

  8. OWASP TOP 10 2017中文译文

    说明:owasp top 10其实有中文官方版本:本文是按着英文版进行翻译而成. 官方中文版:http://www.owasp.org.cn/owasp-project/OWASPTop102017v ...

  9. 使用Redis数据库(2)(三十四)

    除了String类型,实战中我们还经常会在Redis中存储对象,这时候我们就会想是否可以使用类似RedisTemplate<String, User>来初始化并进行操作.但是Spring ...

  10. Ubuntu 14.04下如何更换更新源(更新为163源)

    之前的安装ubuntu桌面版的之后安装yum,vim等会遇到一些问题, 比如:Ubuntu 14.04下如何更换更新源(更新为163源) 解决: http://jingyan.baidu.com/ar ...