-
Notifications
You must be signed in to change notification settings - Fork 137
/
query_params.py
39 lines (31 loc) · 1.17 KB
/
query_params.py
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
38
39
from twisted.internet.task import react
from twisted.internet.defer import inlineCallbacks
import treq
@inlineCallbacks
def main(reactor):
print('List of tuples')
resp = yield treq.get('https://httpbin.org/get',
params=[('foo', 'bar'), ('baz', 'bax')])
content = yield resp.text()
print(content)
print('Single value dictionary')
resp = yield treq.get('https://httpbin.org/get',
params={'foo': 'bar', 'baz': 'bax'})
content = yield resp.text()
print(content)
print('Multi value dictionary')
resp = yield treq.get('https://httpbin.org/get',
params={b'foo': [b'bar', b'baz', b'bax']})
content = yield resp.text()
print(content)
print('Mixed value dictionary')
resp = yield treq.get('https://httpbin.org/get',
params={'foo': [1, 2, 3], 'bax': b'quux', b'bar': 'foo'})
content = yield resp.text()
print(content)
print('Preserved query parameters')
resp = yield treq.get('https://httpbin.org/get?foo=bar',
params={'baz': 'bax'})
content = yield resp.text()
print(content)
react(main, [])