Making HTTP requests using the requests module in Python
As we have seen, the HTTP protocol is a plain text protocol, and while we could implement this protocol by hand, that is very cumbersome. We will thus use the requests
module. This module abstracts the process of requesting and handling the response from an HTTP server. In this first recipe, we will see how to do an initial request against a network device that has RESTCONF enabled. This recipe thus also serves as a verification that RESTCONF is properly enabled on your device.
Getting ready
Open your code editor and start by creating a file called make_request.py
. Next, navigate in your terminal to the same directory in which you just created the make_request.py
file.
How to do it…
Follow these steps to make your first HTTP request using Python and the requests
module:
- Import the
requests
module:import requests
- Create a
requests
session:s = requests.Session()
- Specify the connection information...