Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Cookie选择性地不随请求一起发送_Python_Python 3.x_Cookies_Python Requests_Fiddler - Fatal编程技术网

Python Cookie选择性地不随请求一起发送

Python Cookie选择性地不随请求一起发送,python,python-3.x,cookies,python-requests,fiddler,Python,Python 3.x,Cookies,Python Requests,Fiddler,在Python 3.6中使用requests模块(3.5中也会用到),下面是我代码的要点: sess=requests.Session() login_to_stackexchange(sess) # logs in to SE print(sess.cookies) # see below sess.post("chat.stackexchange.com/something",data=data) # data={"index":stuff} 第3行的cookies是: <Cooki

在Python 3.6中使用
requests
模块(3.5中也会用到),下面是我代码的要点:

sess=requests.Session()
login_to_stackexchange(sess) # logs in to SE
print(sess.cookies) # see below
sess.post("chat.stackexchange.com/something",data=data) # data={"index":stuff}
第3行的cookies是:

<Cookie acct=t=[key here]&s=[key here] for .stackexchange.com/>
<Cookie prov=[key here] for .stackexchange.com/>

但是,当使用Fiddler查看发送的请求时,只发送第一个cookie(prov)。我需要两个cookies来满足我的工作请求

为什么请求只发送一个cookie? 我怎样才能解决这个问题


第3行返回的“完整”cookie:

<Cookie uauth=true for .chemistry.stackexchange.com/>
<Cookie acct=t=[key here]&s=[key here] for .stackexchange.com/>
<Cookie prov=[key here] for .stackexchange.com/>
<Cookie sechatusr=t=[key here] for chat.stackexchange.com/>
<Cookie anon=[key here] for openid.stackexchange.com/>


那么为什么不使用堆栈交换API呢?看,你不必担心欺骗登录。@MartijnPieters该API不支持与聊天室的交互,至少不要重新发明轮子:@MartijnPieters我的问题是,我已经工作了好几个月了,但昨天突然停止了工作,当我诊断出错误时,它来自于cookie处理。我正在尝试修复它,而不是重做一个新的聊天机器人。然后请向我们显示
设置Cookie
标题(传入)和
Cookie
标题(传出),以显示实际的交换是什么。总的来说,我倾向于信任请求cookie处理代码,因为它使用Python中包含的长时间稳定的cookielib库代码。