Libraries: requests Flashcards

(8 cards)

1
Q

Send GET request to URL

A

requests.get('https://api.github.com/events')

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Send POST request with some form data

A

requests.post('https://httpbin.org/post', data={'key': 'value'})

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Send GET request with URL query parameters

A
payload = {'key1': 'value1', 'key2': 'value2'}
r = requests.get('https://httpbin.org/get', params=payload)
# https://httpbin.org/get?key2=value2&key1=value1
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Send GET request with custom User-Agent header

A
r = requests.get(url, headers={'user-agent': 'my-app/0.0.1'})
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Send POST request with JSON payload

A

r = requests.post(url, json={ "name": "test", "value": 123, })

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Response: get decoded response string

A

r.text

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Response: get response JSON

A

r.json()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Response: get status code

A

r.status_code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly