首页 技术 正文
技术 2022年11月6日
0 收藏 347 点赞 288 浏览 511 个字

一、环境安装

1.用pip安装requests模块

>>pip install requests

python接口自动化-get请求

二、get请求

python接口自动化-get请求

1.  url

python接口自动化-get请求

1.1:   response 的返回内容还有很多信息,例如:

r.status_code          #响应状态码
r.content #字节方式的响应体,会自动为你解码 gzip 和 deflate 压缩
r.headers #以字典对象存储服务器响应头,但是这个字典比较特殊,字典键不区分大小写,若键不存在则返回None
r.json() #Requests中内置的JSON解码器
r.url # 获取url
r.encoding # 编码格式
r.cookies # 获取cookie
r.raw #返回原始响应体
r.text #字符串方式的响应体,会自动根据响应头部的字符编码进行解码
r.raise_for_status() #失败请求(非200响应)抛出异常

2.   params  参数

python接口自动化-get请求

2.1   乱码问题的解决: r.content

如果用 r.text 获取到的内容有乱码,可能响应内容是gzip压缩的(非text文本)

这时可以用 r.content 方法,content 会自动解码 gzip 和 deflate 压缩

print(r.content.decode(“utf-8”))

python接口自动化-get请求

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,028
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,518
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,367
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,146
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,781
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,858