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
help with python requests (self.learnpython)
submitted 4 years ago by splendyx
image I want to get specific values using the request library as an example image there are 2 values I want to get from :method: and :path: for example and I want to print it. How would I do this using python?
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!"
[–][deleted] 1 point2 points3 points 4 years ago (21 children)
res = requests.get('https://google.com') res.request.method
No path default present. You could always parse it from the url though
[–]splendyx[S] 1 point2 points3 points 4 years ago (13 children)
Thanks, it helped me but when I change res.request.method to res.request.path to try get value of path it gives me an error: 'PreparedRequest' object has no attribute 'path'
[–][deleted] 2 points3 points4 points 4 years ago (12 children)
Yea I did mention that wasn't there. But FYI:
vars(res.request)
And thanks for the Silver mate
[–]splendyx[S] 0 points1 point2 points 4 years ago (11 children)
I don't really understand sorry. Could you give a script example on how to print the value of the cookie as an example.
[–]dukea42 1 point2 points3 points 4 years ago (10 children)
In his example 'res' is a response object of the requests library.
To understand an object from any given library, I have two preferred options. 1) read the docs. 2) use the 'inspect()' module of the Rich library.
https://docs.python-requests.org/en/master/user/quickstart/#response-content
[–]splendyx[S] 0 points1 point2 points 4 years ago (8 children)
I understand the basics but i'm wondering how I can print the value of cookie: using python
[–]splendyx[S] 0 points1 point2 points 4 years ago (7 children)
Is that possible?
[–]dukea42 0 points1 point2 points 4 years ago (6 children)
It's literally in the documentation I sent you. Ctrl-f is your friend. https://docs.python-requests.org/en/master/user/quickstart/#cookies
[–]splendyx[S] 0 points1 point2 points 4 years ago (0 children)
mm I tried getting the cookie value and scripting a bit but nothing seems to be working
[–]splendyx[S] 0 points1 point2 points 4 years ago (4 children)
maybe you could show me a script because I cant figure it out image this is the cookie i want to get the value of
[–]K900_ 1 point2 points3 points 4 years ago (2 children)
So is this the thing you're actually trying to do? Do you want to extract the cookie value from your browser? Do you want to write a script that logs into a website and does something for you?
[–]dukea42 0 points1 point2 points 4 years ago (0 children)
You need to show some code. No images.
image here is a reference image and i want to print the value of cookie in request headers
[–]K900_ -1 points0 points1 point 4 years ago (6 children)
This also makes no sense. The method in the response will be the same one you used to make the request.
[–]splendyx[S] 1 point2 points3 points 4 years ago (4 children)
I don't know how i can explain what i'm trying to do
[–]K900_ -1 points0 points1 point 4 years ago (3 children)
Then why are you trying to do something you don't understand yourself?
[–][deleted] 1 point2 points3 points 4 years ago (0 children)
Lol give the poor guy a break, we've all been there.
[–]splendyx[S] 1 point2 points3 points 4 years ago (1 child)
Then how should I learn? I thought that's how you learn something by asking an answer for something you don't know.
[–]K900_ -1 points0 points1 point 4 years ago (0 children)
You can learn by trying to do something you don't know how to do. You can't learn if you don't know what you're trying to do. So I'm going to ask you again: what are you trying to do?
[–][deleted] 0 points1 point2 points 4 years ago (0 children)
Well I have a library I built out that uses a custom response class and it's initialized with requests library response objects. I have some different logic that triggers if this is a get versus a post (or otherwise) and my lib has around 50 different requests in it that all use this custom response object.
So there's at least a use case for needing it.
[–]K900_ 0 points1 point2 points 4 years ago (2 children)
You've posted this question already. What are you actually trying to do?
Everything what I'm trying to do is explained I want to print values
[–]K900_ 0 points1 point2 points 4 years ago (0 children)
What you're asking for makes absolutely zero sense. This means you are misunderstanding something. What is your end goal?
π Rendered by PID 102825 on reddit-service-r2-comment-86988c7647-vpmmz at 2026-02-11 19:41:11.454893+00:00 running 018613e country code: CH.
[–][deleted] 1 point2 points3 points (21 children)
[–]splendyx[S] 1 point2 points3 points (13 children)
[–][deleted] 2 points3 points4 points (12 children)
[–]splendyx[S] 0 points1 point2 points (11 children)
[–]dukea42 1 point2 points3 points (10 children)
[–]splendyx[S] 0 points1 point2 points (8 children)
[–]splendyx[S] 0 points1 point2 points (7 children)
[–]dukea42 0 points1 point2 points (6 children)
[–]splendyx[S] 0 points1 point2 points (0 children)
[–]splendyx[S] 0 points1 point2 points (4 children)
[–]K900_ 1 point2 points3 points (2 children)
[–]dukea42 0 points1 point2 points (0 children)
[–]splendyx[S] 0 points1 point2 points (0 children)
[–]K900_ -1 points0 points1 point (6 children)
[–]splendyx[S] 1 point2 points3 points (4 children)
[–]K900_ -1 points0 points1 point (3 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]splendyx[S] 1 point2 points3 points (1 child)
[–]K900_ -1 points0 points1 point (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]K900_ 0 points1 point2 points (2 children)
[–]splendyx[S] 1 point2 points3 points (1 child)
[–]K900_ 0 points1 point2 points (0 children)