File: query_params.py

package info (click to toggle)
python-treq 25.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 596 kB
  • sloc: python: 4,832; makefile: 130
file content (37 lines) | stat: -rw-r--r-- 976 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from twisted.internet.task import react

import treq


async def query_params(reactor):
    print("List of tuples")
    resp = await treq.get(
        "https://httpbin.org/get", params=[("foo", "bar"), ("baz", "bax")]
    )
    print(await resp.text())

    print("Single value dictionary")
    resp = await treq.get(
        "https://httpbin.org/get", params={"foo": "bar", "baz": "bax"}
    )
    print(await resp.text())

    print("Multi value dictionary")
    resp = await treq.get(
        "https://httpbin.org/get", params={b"foo": [b"bar", b"baz", b"bax"]}
    )
    print(await resp.text())

    print("Mixed value dictionary")
    resp = await treq.get(
        "https://httpbin.org/get",
        params={"foo": [1, 2, 3], "bax": b"quux", b"bar": "foo"},
    )
    print(await resp.text())

    print("Preserved query parameters")
    resp = await treq.get("https://httpbin.org/get?foo=bar", params={"baz": "bax"})
    print(await resp.text())


react(query_params)