Requests (Internet)
Requests is a great package used to download information from the Internet. Typically, files are stored locally on a machine, however much of the data students will be working with will be on the Internet.
JSON Data
JSON stands for Javascript Object Notation. These are text-based storage entities that allow for information to be easily extracted.
What is Requests
Requests is a module that allows programmers to specify a URL. After specified, requests will use the proper protocol and download/upload the request information.
To start using Requests, programmers need to import the requests module. Please note that the requests module is not installed by default, so programmers may need to install it using:
python -m pip install requests
import requests
req = requests.get("http://tiny.utk.edu/cosc505/test.data")
print(req.text)
The request will download data from the course website and print it. Programmers can also specify a username and password by using the auth keyword, such as auth=('user', 'pass').
If you pointed your web browser to the given site, you'll see that test.data contains the following information:
Data 1
Line 2
Data 3
Line 4
Data 5
Line 6
This will be exactly what is contained in req.text. So, if your installation of requests is correct, you'll get that information.
Another interesting system is the automatic JSON conversion. Requests will convert a downloaded request into JSON if it's able through req.json(). Notice that json() is a function, unlike req.text.
References
http://python-requests.org/en/master/
Stephen Marz (20190610)