June 2025
Beginner to intermediate
473 pages
13h 30m
English
The linchpin of REST scripts in Python is the requests module, which I already briefly introduced to you in Chapter 17. The module has a disadvantage in that, unlike the urllib module, it must be installed separately using pip:
$ pip install requests (Windows, Linux)$ pip3 install requests (macOS, old Linux distributions)
Instead, the function of the same name can be used to run all conceivable requests without syntactic contortions. The following lines show a simple Get request. The binary result (response.content) is converted to a UTF-8 string via decode and is then output:
import requests# Get requestresponse = requests.get('https://httpbin.org/get?q=123')print(response.content.decode('utf-8'))# {# "args": ...Read now
Unlock full access