Repository navigation
Replies: 1 comment
|
For a dictionary that keeps each cookies_by_scope = {
(cookie.domain, cookie.path, cookie.name): cookie.value
for cookie in client.cookies.jar
}Or retrieve one exact cookie: value = client.cookies.get(
"aliyungf_tc", domain="example.com", path="/"
)Use the domain/path stored in your jar (including a leading dot if present). This is an exact scope lookup, not a lookup of every cookie applicable to a request URL. Supplying just a domain can still be ambiguous if the name exists at multiple paths. For your update question, a plain dictionary works directly when you want cookies with the default scope: client.cookies.update({"theme": "dark"})However, values = {"aliyungf_tc": "updated", "theme": "dark"}
for name, value in values.items():
client.cookies.set(name, value, domain="example.com", path="/")This replaces matching name/domain/path entries and leaves cookies at other scopes alone. References: HTTPX cookie guide and Cookies implementation for 0.28.1. Verified locally with Python 3.14.7 / HTTPX 0.28.1: reproduced |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Can there be a similar
requestspackage that can convert cookies into dict?And how to update cookies through a dictionary?
If you directly use dict to extract, an error will be reported because there is a cookie with the same name.
error:
All reactions