Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cookie doesn't set in the next request #87

Closed
ahrzeroday opened this issue Feb 5, 2025 · 7 comments
Closed

Cookie doesn't set in the next request #87

ahrzeroday opened this issue Feb 5, 2025 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@ahrzeroday
Copy link

ahrzeroday commented Feb 5, 2025

Hi,
When I set a cookie in the request, the cookie doesn't get stored with the other cookies that the request gives me. Additionally, if the request has a redirect, my cookie is only sent with the first request, and the other redirected requests do not have my cookie.

Code:
import primp client = primp.Client(impersonate="chrome_130", impersonate_os="windows") cookie = {"TheCookie": "IWantToSet"} client.cookies = cookie resp = client.get("https://httpbin.org/cookies/set?TestCookie=First")

This link redirected to "https://httpbin.org/cookies". If you look at the header of this link, you can see just this:

cookie: TestCookie=First

And also, if I want to set a cookie for a URL without redirecting, it only sets my cookie for the first request. If I call that URL again with same client, my cookie is not stored. Additionally, if I want to set the cookie on a specific domain name, there is no option for it.

Thanks for your support.

@deedy5
Copy link
Owner

deedy5 commented Feb 20, 2025

Fixud in #96

@deedy5 deedy5 closed this as completed Feb 20, 2025
@ahrzeroday
Copy link
Author

Hi,
I tested it again, but it doesn't work. Maybe I was wrong. Can you give me a sample code that works?

@deedy5
Copy link
Owner

deedy5 commented Feb 20, 2025

client.cookies needs improvement.
Set cookies this way:

import primp

cookie = {"TheCookie": "IWantToSet"}
client = primp.Client(impersonate="chrome_130", impersonate_os="windows", cookies=cookie)
resp = client.get("https://httpbin.org/cookies/set?TestCookie=First")
print(resp.text)

or

import primp

cookie = {"TheCookie": "IWantToSet"}
client = primp.Client(impersonate="chrome_130", impersonate_os="windows")
resp = client.get("https://httpbin.org/cookies/set?TestCookie=First", cookies=cookie)
print(resp.text)

@deedy5 deedy5 self-assigned this Feb 20, 2025
@deedy5 deedy5 added the bug Something isn't working label Feb 20, 2025
@ahrzeroday
Copy link
Author

I tested your code, and I realized we can't set a cookie for a special domain. Is that correct?
I found out that when I run this code:

import primp

cookie = {"TheCookie": "IWantToSet"}
client = primp.Client(impersonate="chrome_130", impersonate_os="windows", cookies=cookie)
resp = client.get("https://httpbin.org/cookies/set?TestCookie=First")
print(resp.text)
print(resp.cookies)

resp.cookies gives me an empty dictionary. Also, when I run this code:

import primp

cookie = {"TheCookie": "IWantToSet"}
client = primp.Client(impersonate="chrome_130", impersonate_os="windows", cookies=cookie)
resp = client.get("https://httpbin.org/cookies/set?TestCookie=First")
print(resp.text)
client.cookies={"TheCookie": "IWantToSet2"}
resp = client.get("https://httpbin.org/cookies/set?TestCookie=First")
print(resp.text)

It doesn't update the cookie.

@deedy5
Copy link
Owner

deedy5 commented Feb 20, 2025

resp.cookies

import primp

client = primp.Client(impersonate="chrome_130", impersonate_os="windows")
resp = client.get("https://nytimes.com")
print(resp.cookies)

updating cookies

import primp

client = primp.Client(impersonate="chrome_130", impersonate_os="windows")

cookie = {"TheCookie": "IWantToSet"}
resp = client.get("https://httpbin.org/cookies/set?TestCookie=First", cookies=cookie)
print(resp.text)

cookie={"TheCookie": "IWantToSet2"}
resp = client.get("https://httpbin.org/cookies/set?TestCookie=First", cookies=cookie)
print(resp.text)

cookie={"TheCookie3": "IWantToSet3"}
resp = client.get("https://httpbin.org/cookies/set?TestCookie=First", cookies=cookie)
print(resp.text)

@deedy5
Copy link
Owner

deedy5 commented Feb 20, 2025

updating cookies 2

import primp

client = primp.Client(impersonate="chrome_130", impersonate_os="windows")

cookie = {"TheCookie": "IWantToSet"}
client.set_cookies("https://httpbin.org", cookie)
resp = client.get("https://httpbin.org/cookies/set?TestCookie=First")
print(resp.text)

cookie={"TheCookie": "IWantToSet2"}
client.set_cookies("https://httpbin.org", cookie)
resp = client.get("https://httpbin.org/cookies/set?TestCookie=First")
print(resp.text)

cookie={"TheCookie3": "IWantToSet3"}
client.set_cookies("https://httpbin.org", cookie)
resp = client.get("https://httpbin.org/cookies/set?TestCookie=First")
print(resp.text)

@deedy5
Copy link
Owner

deedy5 commented Feb 20, 2025

resp.cookies 2

import primp

client = primp.Client(impersonate="chrome_130", impersonate_os="windows")
resp = client.get("https://nytimes.com")
print(resp.cookies)
print(client.get_cookies("https://nytimes.com"))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants