Libraries and APIs Flashcards
How do you get a response from an API?
requests.get(URL) returns the response code
What do the different response codes mean?
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 do you get json from a response?
url.json in some cases
response.text (often formatted as json)
response.json() json data from response
What does JSON stand for?
JavaScript Object Notation
How to convert between json and python objects?
json.loads(str) makes a python object from a string
json.dumps(obj) makes json from a python object
How to use json.dumps() to format json into something more readable?
json.dumpts(obj=some_obj, indent=4, sort_keys=True)
sort_keys=True skips unreadable data
How to use parameters with response.get()?
parameters = dict
response.get(url, params=parameters)
dir(module) does what?
Gets a list of the functions and variables in the module