python发送cookie请求_Python请求发送多个Cookie

How would you go about sending multiple cookies with python requests

the documentation only gives

url = 'http://httpbin.org/cookies'

cookies = dict(cookies_are='working')

r = requests.get(url, cookies=cookies)

r.text

Here is what i have tried currently

url = 'http://192.168.0.57/dvwa/vulnerabilities/fi/?page=include.php'

cookies = dict(cookies_are=options.cookie)

r = requests.get(url, cookies=cookies, headers=headers)

when i run my script with

--cookie="security=Low; PHPSESSID=4edca0525666fbbe319f50ce3630b4a9"

the security cookie is not recognised but the PHPSESID is

解决方案

The cookies parameter is a dict where the key is cookie name and the value is cookie value. So while your cookie-input is cookie string you have two ways to use it with requests:

1) parse cookie string and make the dict from it like the following:

import requests

from Cookie import SimpleCookie

cookie_string = options.cookie

cookie = SimpleCookie(cookie_string)

cookie_dict = {k: v.value for k, v in cookie.iteritems()}

requests.get(url, cookies=cookie_dict)

2) simply set it as Cookie header:

import requests

from Cookie import SimpleCookie

cookie_string = options.cookie

headers = {'Cookie': cookie_string}

requests.get(url, headers=headers)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值