Python+requests请求响应:"msg":"登录过时"

1、出错原代码:

 import requests
import json
#页面按条件搜索返回相应数据的接口测试
s = requests.session()
url = "http://47.106.203.20:8000/ssposs2/api/sspquery/query"
par = {
"order":"",
"orderField":"",
"pageIndex":1,
"pageSize":20,
"filename":"query-export",
"action":"download",
"service":"wf",
"sh":"n",
"provId":"",
"cityId":"",
"brockId":"",
"imei":"",
"pliceNo":"",
"zfHphm":"粤A61933",
"gtDate":"",
"shStatus":"",
"jgDataStatus":"",
"wfType":"",
"dataType":"",
"gtStartDate":"2019-07-17 15:34:01",
"gtEndDate":"2019-08-16 15:34:01"
}
header = {
'connection':'keep-alive',
'Content-Type':'application/json'
}
r =s.post(url,data=json.dumps(par),headers=header)
print(r.status_code)
print(r.text)

2、运行结果:

 200
{"result":false,"msg":"登录过时","code":""}#接口响应成功的,但是请求内容登录过时。

因为该接口测试的前提是在登录页面后进行条件查询,所以是要有登录的cookie值,但是这里没有获取前一个页面登录的cookie值所以导致请求出错

二修改后:

import requests
import json
s = requests.session()
url = "http://47.106.203.20:8000/ssposs2/api/sspquery/query"
par = {
"order":"",
"orderField":"",
"pageIndex":1,
"pageSize":20,
"filename":"query-export",
"action":"download",
"service":"wf",
"sh":"n",
"provId":"",
"cityId":"",
"brockId":"",
"imei":"",
"pliceNo":"",
"zfHphm":"粤A61933",
"gtDate":"",
"shStatus":"",
"jgDataStatus":"",
"wfType":"",
"dataType":"",
"gtStartDate":"2019-07-17 15:34:01",
"gtEndDate":"2019-08-16 15:34:01"
}
header = {
'connection':'keep-alive',
'Content-Type':'application/json'
}
#*******************************************
#加上登录页面的cookie
cookie = {
'JSESSIONID':'d192ae01-8b58-4033-85c1-d7e44a06bd00',
'root-Token':'ceshi'
}
#*******************************************
r =s.post(url,data=json.dumps(par),headers=header,cookies=cookie)
print(r.status_code)
print(r.text)

2、运行结果:

200
{"result":true,"msg":null,"code":null,"data":{"content":[],"pageable":{"sort":{"unsorted":true,"sorted":false,"empty":true},"pageNumber":0,"pageSize":20,"offset":0,"unpaged":false,"paged":true},"last":true,"totalPages":0,"totalElements":0,"first":true,"sort":{"unsorted":true,"sorted":false,"empty":true},"numberOfElements":0,"size":20,"number":0,"empty":true}}

python+requests 请求响应文本出错返回“登录超时”的更多相关文章

  1. Python3 使用requests请求,解码时出错:'utf8' codec can't decode byte 0x8b in position 1: invalid start byte

    requests请求的响应内容能够通过几个属性获得: response.text 为解码之后的内容,解码会根据响应的HTTP Header中的Content-Type选择字符集.例如 "'C ...

  2. Python3 使用requests请求,解码时出错:'utf8' codec can't decode byte 0x83 in position 1: invalid start byte

    requests请求的响应内容能够通过几个属性获得: response.text 为解码之后的内容,解码会根据响应的HTTP Header中的Content-Type选择字符集.例如 1 " ...

  3. python http 请求 响应 post表单提交

    1. 查看请求 响应情况 print(response.text) print(response.headers) print(response.request.body) print(respons ...

  4. python requests请求卡住问题

    最近经常接到别人反馈某个爬虫工具程序没有正常运行,需要下载的资讯数据也没有及时进行收录. 刚开始以为可能是机器的问题,偶尔机器会出现程序运行中途卡住的情况. 但随着异常的情况越来越频繁,我便只好去排查 ...

  5. python requests 请求禁用SSL警告信息解决

    Python3 requests模块发送HTTPS请求,关闭SSL 验证,控制台会输出以下错误: InsecureRequestWarning: Unverified HTTPS request is ...

  6. python requests 请求的封装

    #encoding=utf-8import requestsimport jsonclass HttpClient(object):    def __init__(self):        pas ...

  7. requests请求库

    # coding = utf-8 """ 同urllib一样 requests 也是发送http请求的第三方库 兼容Python2和3 实现了http的绝大部分功能. 安 ...

  8. Katalon Studio之请求响应中文乱码解决方法

    最近在用Katalon做接口测试过程中发现请求响应消息中返回的中文均为乱码,这是因为我们使用的系统环境在初始安装时选择的中文简体,导致windows系统默认编码格式为GBK,但是KS的编码格式是UTF ...

  9. Python+requests 发送简单请求--》获取响应状态--》获取请求响应数据

    Python+requests 发送简单请求-->获取响应状态-->获取请求响应数据 1.环境:安装了Python和vscode编译器(Python自带的编译器也ok).fiddler抓包 ...

随机推荐

  1. HGOI 20191031am 题解

    Problem A Divisors 给出$m$个不同的正整数$a_i$,设数论函数 ​​​$f(k) = \sum\limits_{i = 1}^{n} [(\sum\limits_{j = 1}^ ...

  2. 清北学堂-贪心-bfs

    输入样例: 3 5 10 5 4 10 8 1 10 1 3 1 4 1 5 1 3 2 1 2 5 4 3 4 3 4 5 5 1 1 4 4 6 1 9 4 7 2 9 5 10 5 2 8 8 ...

  3. 2019ICPC上海网络赛 A Lightning Routing I 点分树(动态点分治)+线段树

    题意 给一颗带边权的树,有两种操作 \(C~e_i~w_i\),将第\(e_i\)条边的边权改为\(w_i\). \(Q~v_i\),询问距\(v_i\)点最远的点的距离. 分析 官方题解做法:动态维 ...

  4. 关于kafka定期清理日志后再消费报错kafka.common.OffsetOutOfRangeException的解决

    环境: kafka  0.10 spark  2.1.0 zookeeper  3.4.5-cdh5.14.0 公司阿里云测试机,十月一放假前,没有在继续消费,假期过后回来再使用spark strea ...

  5. Ubuntu切换登录用户和root用户

    https://blog.csdn.net/master_ning/article/details/80733818

  6. CSS子元素在父元素中水平垂直居中的几种方法

    1. 水平居中(margin: auto;)子父元素宽度固定,子元素上设置 margin: auto; 子元素不能设置浮动,否则居中失效. #div1{ width: 300px; height: 3 ...

  7. vue 复制内容到粘贴板

    首先是npm安装依赖包:npm install clipboard --save 导入组件:import Clipboard from "clipboard"; html如图: c ...

  8. LeetCode 240. 搜索二维矩阵 II(Search a 2D Matrix II)

    题目描述 编写一个高效的算法来搜索 m x n 矩阵 matrix 中的一个目标值 target.该矩阵具有以下特性: 每行的元素从左到右升序排列. 每列的元素从上到下升序排列. 示例: 现有矩阵 m ...

  9. HearthBuddy炉石兄弟 如何调试ai

    Sepefeets's update to botmaker's Silverfish AI This AI is a Custom Class for Hearthranger and Hearth ...

  10. [学习]sentinel中的DatatSource(一) ReadableDataSource

    sentinel是今年阿里开源的高可用防护的流量管理框架. git地址:https://github.com/alibaba/Sentinel wiki:https://github.com/alib ...