简体   繁体   中英

Missing cookies in HTTP response Python

I'm building an extra provider for Sickbeard and having problems with my cookies. I've been looking for a long time now after why cookies are missing in the HTTP Response when using requests .

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:

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


The cookies that I get (and want) when logging into the provider are __cdfuid | 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. The other two just has expiration and the actual data.

response.cookies contains only the cookies set by that response . If you are redirected you may find some cookies were set by the redirect. These will not be present on response.cookies , though they will be present on 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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