File: using_cookies.py

package info (click to toggle)
python-treq 24.9.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 592 kB
  • sloc: python: 4,895; makefile: 130
file content (19 lines) | stat: -rw-r--r-- 482 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from twisted.internet.task import react
from _utils import print_response

import treq


async def main(reactor):
    resp = await treq.get("https://httpbin.org/cookies/set?hello=world")

    jar = resp.cookies()
    [cookie] = treq.cookies.search(jar, domain="httpbin.org", name="hello")
    print("The server set our hello cookie to: {}".format(cookie.value))

    await treq.get("https://httpbin.org/cookies", cookies=jar).addCallback(
        print_response
    )


react(main)