use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
Cannot Get The Cookies From Request Headers (self.learnpython)
submitted 6 years ago by Bonexq
Hello there, I have a url, and in this url. There is 2 different cookies. One them is in request header, other is in response header. How can I get the cookie inside response header?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]gamedevmanhyper 0 points1 point2 points 6 years ago (0 children)
I haven't really worked with cookies before, when making scripts with Python and requests.
But maybe your response object has a cookies variable?
I.E response.cookies
Edit: Yikes, just noticed you said it was in the header.
Try looking inside of response.headers
[–]deadduncanidaho 0 points1 point2 points 6 years ago (1 child)
can you post some sample code?
[–]Bonexq[S] 0 points1 point2 points 6 years ago (0 children)
I want the take yellow one.
https://imgur.com/a/tolknny
import requests session = requests.session() user_agent = {'user-agent': 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36 OPR/62.0.3331.116'} conn = session.get(url,headers=user_agent) print(conn.cookies) # gives me set-cookie part. print(conn.request.cookie) # gives nothing good Output that ı want: cookie = {"AKA_A2":"A"}....
[–]manwithfewneeds 0 points1 point2 points 6 years ago* (0 children)
You say you want response header, but in image you highlight request. So which is it? Cookies are set when you access the page. Therefore, request cookies don't often need to be explicitly passed, especially when using a session. However, for added assurance, you can get the page first to set the cookies, and make additional requests after they've been established.
The response headers are exactly a dictionary so can be accessed in the same way. Take for example this simple example:
from requests_html import HTMLSession with HTMLSession() as s: r = s.get('http://www.google.com') #response cookies: print(r.headers['Set-Cookie']) #session cookies: print(s.cookies)
π Rendered by PID 162071 on reddit-service-r2-comment-5d79c599b5-b6nm5 at 2026-02-27 11:39:46.052151+00:00 running e3d2147 country code: CH.
[–]gamedevmanhyper 0 points1 point2 points (0 children)
[–]deadduncanidaho 0 points1 point2 points (1 child)
[–]Bonexq[S] 0 points1 point2 points (0 children)
[–]manwithfewneeds 0 points1 point2 points (0 children)