S
S
sddvxd2017-01-27 14:45:39
Python
sddvxd, 2017-01-27 14:45:39

Where do cookies go?

Good day
When I look at the headers from the browser and find SetCookie in the server responses, which are not clear where they go
. I don’t find similar cookies in the browser’s cookie database, approx.

Set-Cookie: remember_user_token=blablabla--blabla; domain=.site.com; path=/;expires=Fri, 10-Feb-2017 10:04:58 GMT; HttpOnly

and the second line also contains a set of cookies:
Set-Cookie: _site_session=blablabla--blabla; domain=site.com; path=/; HttpOnly

In the cookie table, it is this site that has cookies with the names "__utma", "__utmz", "__utmb" and only they are there. They explained to me that this is a tracking cookie
. But I don’t find these cookies: "remember_user_token" and "_site_session"
When I pull out cookies from a session, I get only "remember_user_token"
and also, why, when I declare a session, headers cannot be passed to it?
import requests
from bs4 import BeautifulSoup

url = "http://site.com"

heads = {'User-Agent' : 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:51.0)Gecko/20100101 Firefox/51.0', 'Host':'site.com'}

s = requests.Session()

response = s.get(url, headers =heads)
print(response.headers.values)

#{'User-Agent': 'python-requests/2.12.4', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'}

And this is how they are transmitted, why - I myself do not know:
s = requests.Session()
s.headers = heads

response = s.get(url, headers = s.headers)
print(response.headers.values)

#{'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:51.0)Gecko/20100101 Firefox/51.0', 'Host': 'site.com'}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Mindlin, 2017-01-27
@kgbplus

Because this is what it
should be:
response = s.get(url, headers =heads)

S
shamanovski, 2017-01-28
@shamanovski

heads = {'User-Agent' : 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:51.0)Gecko/20100101 Firefox/51.0', 'Host':'site.com'}

s = requests.Session()

response = s.get(url, headers =heads)
print(response.headers.values)

the response object contains information about the response to your request (cookies, headers, body, etc.)
so you get the headers sent from the server you sent the request to.
To view the headers you send, use the headers attribute of the Session() object
Are you able to log into the site using requests? If yes, then all received cookies can be accessed through the cookies attribute on the same Session() object

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question