cookies放请求头还是请求体?

文章讲述了在Python中使用requests库通过设置cookies和请求头访问特定URL(如`https://bibfx.flyhs-system.com/da-tax/api/manage/reportDataPreview`),并演示了两种方法:一种是将cookies直接加入请求头,另一种是先将cookies转换为字典形式再传递。
摘要由CSDN通过智能技术生成
ac_login = requestses.session()
cookies = ac_login.cookies

url_peak = "your data_url"
params = { 
            "dashBoardReportId" : "0fef1a97-fac6-4bb9-ac52-e352c88130fc" ,
            "where" : json.dumps({"conditions":[{"field":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":"date_format(trace,'%Y-%m-%d %H:%m:%s')","isEXPR":True},"operator":">=","value":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":f"'{begin_time}'","isEXPR":True},"command":"AND"},{"field":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":"date_format(trace,'%Y-%m-%d %H:%m:%s')","isEXPR":True},"operator":"<","value":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":f"'{end_time}'","isEXPR":True},"command":"AND"}]})
}


#  ----------------------------------------------  1. cookies放请求头  -------------------------------------------
headers1 = { "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36"
           ,'Cookie': '; '.join([f"{cookie.name}={cookie.value}" for cookie in cookies]) # 或直接复制
           }

respon1 = requests.get(url = url_peak,headers = headers1,params = params)
respon1.text

# ----------------------------------------------  2. cookies不放请求头  -------------------------------------------
headers2 = {
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36",
}

dict_cookie = requests.utils.dict_from_cookiejar(cookies)

respon2 = requests.get(url=url_peak,headers=headers2,cookies= dict_cookie,params =params )
respon2.text

url_peak = “https://bibfx.flyhs**-ystem.com/da-**tax/api/manage/reportDataPreview”

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值