Python has a useful high-level HTTP client built into the standard library: urllib.request.urlopen. The default function opens a variety of protocols, even allowing local. filesystem access withURLs. Python's built-in OpenerDirector class offers just such an opportunity to streamline the function. It will still follow redirects automatically, and raise an exception for any HTTP status code that isn't in the 200s or 300s. The code above communicates the lesson "sanitize your user inputs"
Company Mentioned
Jonathan Bowman
@bowmanjd
Constantly learning software development, Python, Linux, containers, and a little Rust. Thinks regex is fun.