Install the requests library and use it to send GET and POST calls to real public APIs, inspect response objects, handle HTTP errors with raise_for_status(), and catch network failures with try/except. Every request in this lesson includes an explicit timeout ā the single most important habit for production HTTP scripts. The lesson closes by importing load_config() from lesson 304's layered_config.py to show how api_base_url flows from the config layer directly into requests calls.
Create the lesson-401 directory, activate the virtual environment from lesson 101, and install the requests library. Confirm the version and explore the top-level objects the package exposes.
mkdir -p ~/devops-python/lesson-401cd ~/devops-python/lesson-401source ~/devops-python/lesson-101/devops-env/bin/activatepip install 'requests>=2.31'pip show requests | grep -E 'Name|Version|Location'python3 -c "import requests; print('requests version:', requests.__version__); print('Key classes:', [x for x in dir(requests) if not x.startswith('_') and x[0].isupper()])"python3 -c "import requests; help(requests.get)" 2>&1 | head -20requests is not part of the Python standard library ā it must be installed from PyPI.
The >=2.31 pin avoids older versions with known CVEs. pip show confirms the installed version and where the package lives on disk.
The third command lists the public classes that requests exposes: Response, Session, Request, and the exception types (HTTPError, Timeout, ConnectionError, etc.).
These are the objects you will use in every step of this lesson.
pip show prints Name: requests and a version of 2.31 or later.
The class list includes Response, Session, HTTPError, Timeout, and ConnectionError. help(requests.get) shows the function signature; in requests >=2.32 the signature reads get(url, params=None, **kwargs: Unpack[GetKwargs]) ā timeout is one of the keyword arguments accepted through **kwargs rather than listed explicitly in the signature.