美文网首页
python接口自动化1-发送get请求

python接口自动化1-发送get请求

作者: 恶毒女配的日常 | 来源:发表于2020-12-11 13:05 被阅读0次

    1、环境安装

    pip install requests

    安装

    2、get请求

    (1)导入requests,通过get访问url

    (2)调用响应(response)中的status_code查看状态码 

    注:200只表示服务器地址是否正确,不能证明功能是否正确,需要通过文本信息查看功能是否正确

    get请求

    如图所示 获得的文本信息乱码,因为百度首页响应内容是gzip压缩的,非text文本,此时需要执行为正确编码即可:response.encoding = response.apparent_encoding

    解决乱码

    3、params

    (1)添加get请求,url为:http://zzk.cnblogs.com/s/blogpost?Keywords=1

    (2)请求参数Keywords=1 以字典形式传参:{'Keywords':'1'}

    (3)多个参数:{'key1':'value1', 'key2':'value2', 'key3':'value3'}

    请求参数

    4、response响应

    响应返回类型:

    相关文章

      网友评论

          本文标题:python接口自动化1-发送get请求

          本文链接:https://www.haomeiwen.com/subject/peazwktx.html