标签:false code cookies com main request 就会 param bsp
登陆后,请求一些接口,使需要验证cookies的,如果没有,就会报用户未登陆,进行不了请求,有三种方法
1、拿到登陆接口的cookies,然后请求其他接口时,传入登陆的cookies
login_cookies = requests.post(login_url,login_param,verify = False).cookies
api_response = requests.post(url,param,verify =False,cookies= login_cookies).json()
2、创建session会话
s = requests.session() s.post(login_url,login_param,verify = False) response=s.post(url,param,verfy=False).json()
3、RequestsCookieJar
login_cookies = requests.post(login_url,login_param,verify = False).cookies,打印出来:<RequestsCookieJar[<Cookie zssid=eff18456fc6e45b2e4d03fabfdd98393 for api-uat.firstbx.com/>]> ,如果有多个cookies,多次set
jar= requests.cookies.RequestsCookieJar() jar.set(‘zssid‘,‘eff18456fc6e45b2e4d03fabfdd98393‘,domain = ‘‘api-uat.firstbx.com) requests.post(url,paramverify=False,cookies = jar)
或者
jar= requests.cookies.RequestesCookieJar() jar.set(‘zssid‘,‘eff18456fc6e45b2e4d03fabfdd98393‘,domain = ‘‘api-uat.firstbx.com) s.post(url,paramverify=False,cookies = jar)
或者
s.cookies.update(jar)
requests.cookies.update(jar)
python 登陆后的请求接口保持cookies,session
标签:false code cookies com main request 就会 param bsp
原文地址:https://www.cnblogs.com/1376402226-yuyu/p/13606899.html