重载的方式写Python的post请求
#encoding=utf-8
#__author__="Lanyangyang" import unittest
import requests
import json # This is a public post method.
def test_public_post(self, url, path, params): # post request method
response = requests.post(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.post(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.post(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_post call success") # This is a public post method, include headers
def test_public_post(self, url, path, params,headers): # post request method
response = requests.post(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.post(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.post(url=url + path, params=params,headers=headers).json()
r = json.dumps(response2, indent=2, sort_keys=True) #Print response text in JSON format
print("Print response text")
print(r) print("test_public_post call success") # This is a public post method, include headers,no param
def test_public_post(self, url, path,headers): # post request method
response = requests.post(url=url + path,headers=headers)
# Is the return status code 200?
self.assertEqual(response.status_code, 200, msg="状态码不是200")
# Is the return message SUCCESS?
response_text = requests.post(url=url + path, headers=headers).text
# 将响应内容转换成字典格式
response_dict = json.loads(response_text)
# 获取response message字段的值
response_message = response_dict['message']
# 判断message的值
self.assertEqual(response_message, 'SUCCESS', msg='返回值不是SUCCESS')
print(response.text) # 以json格式输出返回文本
response2 = requests.post(url=url + path,headers=headers).json()
r = json.dumps(response2, indent=2, sort_keys=True)
print("返回信息如下:")
print(r) print("test_public_post调用成功")
重载的方式写Python的post请求的更多相关文章
- 重载的方式写Python的get请求
#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语法实现传递的,仅仅要定义了 ...
随机推荐
- Win7无法保存共享帐户密码
每次机器重启完之后,网络共享的密码总是要重新输入. [记住我的凭据]选项不起作用. 查到了下面百度经验的文章,挺靠谱的. https://jingyan.baidu.com/article/59a01 ...
- 验证码之SimpleCaptcha (二)
上回说到了简单的使用simpleCaptcha,这次我们这次我们将讲解扩张simpleCaptcha. 回到正题,我们需要一些自定义的验证码,比如验证码的字体大小,背景,颜色等等,默认的验 ...
- spring cloud: Hystrix(六):feign的注解@FeignClient:fallbackFactory(类似于断容器)与fallback方法
fallbackFactory(类似于断容器)与fallback方法 feign的注解@FeignClient:fallbackFactory与fallback方法不能同时使用,这个两个方法其实都类似 ...
- 国外(英文)——WPF较好的奇葩问题解决网站
https://stackoverflow.com/questions/6415908/c-sharp-wpf-datagrid-vertical-scroll
- Search中的剪枝-奇偶剪枝
设有一矩阵如下: 0 1 0 1 0 1 1 0 1 0 1 0 0 1 0 1 0 1 1 0 1 0 1 0 0 1 0 1 0 1 从为 0 的格子走一步,必然走向为 1 的格子 .//只能走四 ...
- PTA L2-002 链表去重
题目链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805072641245184 第一次做链表题,有时间多看看 解释 ...
- C# 条件表达式max=(a>b)?a:b;含义
a?b:c 这个是条件表达式,表示如果a为真,则表达式值为b,如果a为假,则表达式值为c条件表达式具体说明如下条件语句: if(a>b) max=a; else max=b; 可用条件表达式写为 ...
- 2017-4-28/PHP实现Redis
谈一谈Redis的数据结构,如果换做PHP,怎么实现?如果再考虑用上LFU或LRU,又该如何实现? Redis的数据结构有String.List.Set.Sorted Set.Hash等,而PHP ...
- HBase环境搭建、shell操作及Java API编程
一. 1.掌握Hbase在Hadoop集群体系结构中发挥的作用和使过程. 2.掌握安装和配置HBase基本方法. 3.掌握HBase shell的常用命令. 4.使用HBase shell命令进行表的 ...
- [CodeForces - 614D] D - Skills
D - Skills Lesha plays the recently published new version of the legendary game hacknet. In this ver ...