-
Notifications
You must be signed in to change notification settings - Fork 0
Python Requests Library
The Requests is a simple HTTP library for Python developers. It allows developers to easily utilize get, request, and other important commands that are a part of HTTP. There are several different ways to implement the use of HTTP, as over the years, many APIs and applications have been developed across multiple programming languages. In the case of Python, the Requests library is what is
There are several important aspects of the Requests library, from basic functions such as get and post to the more advanced techniques such as Certificate generation, proxy interactions, etc. At this moment, we only care about the basic functionalities due to the server being able to handle everything else for us. The functions we are going to look at are the get, post, and status functions.
The .get function allows a user to pull data from the server for further utilization.
r = requests.get('https://api.github.com/events')
The .post function sends the data in whatever format the server accepts.
r = requests.post('https://httpbin.org/post', data=payload)
The .status function allows the user to check for error codes such as 404, 403, and 200 to make sure that the data sent to server was accepted.
if (r.status_code == 403) { print("Error Code...") }
Since this is a Python library, it is required to have the 'pip' package manager, which allows developers to install various programs. The specific pip command is as follows: pip install requests