#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. JDK常用工具

    JDK的命令行工具 jps 查看正在使用的jvm机器进程号. 常用命令,-l显示正在运行的jar包或者软件(基于jvm),-v显示当前进程详细的jvm参数 jps -l jps -v javap 反汇 ...

  2. Tree Requests CodeForces - 570D (dfs水题)

    大意: 给定树, 每个节点有一个字母, 每次询问子树$x$内, 所有深度为$h$的结点是否能重排后构成回文. 直接暴力对每个高度建一棵线段树, 查询的时候相当于求子树内异或和, 复杂度$O((n+m) ...

  3. vue element upload图片 回显问题

      beforeUpload (file) { var _this = this; var reader = new FileReader(); reader.readAsDataURL(file); ...

  4. sqlserver 优化

    避免在索引列上使用计算 where子句中,如果索引列是函数的一部分,优化器将不使用索引而使用全表扫描.例如: (低效)select ... from [dept] where [sal]*12> ...

  5. 《高性能SQL调优精要与案例解析》——10.4_SQL语句改写部分文档

    应各位读者要求,现将<高性能SQL调优精要与案例解析>中<10.4 SQL语句改写>部分整理成电子文档,上传至群共享文件(群号:298176197): 或者通过如下链接下载: ...

  6. Nodejs+mysql+Express: 一个简单的博客

    推荐网址: https://github.com/nswbmw/N-blog/blob/backup/book/%E7%AC%AC1%E7%AB%A0%20%E4%B8%80%E4%B8%AA%E7% ...

  7. OpenSSH隐藏版本号教程

    1.查看当前OpenSSH版本号 sshd -v #sshd并没有-v选项,这并不是重点重点是这样能曝出版本号 2.查看sshd位置 which sshd 3.备份sshd cp /usr/sbin/ ...

  8. Linux用户创建/磁盘挂载相关命令

    命令 作用 常用参数说明 groupadd 增加用户组 -g指定组id groupmod 修饰用户组 参数和groupadd类似 groupdel 删除用户组 直接组名没参数 useradd 增加用户 ...

  9. windows mfc 程序,不同程序通信和互斥

    1. 共享内存(项目中使用过) 我转备份文章:http://www.cnblogs.com/swing07/p/8087686.html CreateFileMapping 或 OpenFileMap ...

  10. py 正在爬取第%d页的美眉图

    #coding=utf-8import reimport requestsfrom bs4 import BeautifulSoupnums = 1num = 1while True: url = & ...