简体   繁体   English

在HTTP响应Python中缺少cookie

[英]Missing cookies in HTTP response Python

I'm building an extra provider for Sickbeard and having problems with my cookies. 我正在为Sickbeard建立一个额外的提供商,并且我的cookie存在问题。 I've been looking for a long time now after why cookies are missing in the HTTP Response when using requests . 我一直在寻找很长一段时间之后为什么在使用请求时HTTP响应中缺少cookie。

login_params = {'uid': sickbeard.PROVIDER_USERNAME,
                'pwd': sickbeard.PROVIDER_PASSWORD,
               }

try:
    response = self.session.post(self.urls['login'], data=login_params, timeout=30)
except (requests.exceptions.ConnectionError, requests.exceptions.HTTPError), e:
    logger.log(u'Unable to connect to ' + self.name + ' provider: ' +ex(e), logger.ERROR)
    return False


The response only contains one cookie the __cdfuid cookie: 响应只包含一个__cdfuid cookie的cookie:

requests.utils.dict_from_cookiejar(self.session.cookies)['__cfduid']


The cookies that I get (and want) when logging into the provider are __cdfuid | 登录提供程序时我得到(并且想要)的cookie是__cdfuid | uid | uid | pass : 通过

requests.utils.dict_from_cookiejar(self.session.cookies)['__cfduid']
requests.utils.dict_from_cookiejar(self.session.cookies)['uid'] #Not passed
requests.utils.dict_from_cookiejar(self.session.cookies)['pass'] #Not passed


I don't know if it matters but the __cdfuid cookie is the only one that has HttpOnly and path=/ parameters set. 我不知道它是否重要,但__cdfuid cookie是唯一一个设置了HttpOnlypath = /参数的cookie。 The other two just has expiration and the actual data. 其他两个只有到期和实际数据。

response.cookies contains only the cookies set by that response . response.cookies仅包含该响应设置的cookie。 If you are redirected you may find some cookies were set by the redirect. 如果您被重定向,您可能会发现重定向设置了一些cookie。 These will not be present on response.cookies , though they will be present on response.history[i].cookies . 这些不会出现在response.cookies ,尽管它们将出现在response.history[i].cookies

You should always examine the cookies dictionary on the Session , not the responses, if you want to get a full idea of what cookies have been set. 如果您想要全面了解已设置的cookie,您应该始终检查Session上的cookie字典,而不是响应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM