Libraries and APIs Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

How do you get a response from an API?

A

requests.get(URL) returns the response code

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

What do the different response codes mean?

A

200: Everything went okay.
301: You are being redirected (domain or endpoint may have changed)
401: You are not authenticated.
403: Forbidden. You do not have permission.
404: Resource not found.
503: Server is not ready to handle the request.

1xx: received, processing. Information code.
2xx: success
3xx: redirection
4xx: client error
5xx: server error

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

How do you get json from a response?

A

url.json in some cases
response.text (often formatted as json)
response.json() json data from response

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

What does JSON stand for?

A

JavaScript Object Notation

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

How to convert between json and python objects?

A

json.loads(str) makes a python object from a string
json.dumps(obj) makes json from a python object

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

How to use json.dumps() to format json into something more readable?

A

json.dumpts(obj=some_obj, indent=4, sort_keys=True)
sort_keys=True skips unreadable data

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

How to use parameters with response.get()?

A

parameters = dict
response.get(url, params=parameters)

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

dir(module) does what?

A

Gets a list of the functions and variables in the module

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