paint-brush
How To Harden And Simplify Urlopen Function In Pythonby@bowmanjd
574 reads
574 reads

How To Harden And Simplify Urlopen Function In Python

by Jonathan Bowman4mMarch 22nd, 2021
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

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

Mention Thumbnail
featured image - How To Harden And Simplify Urlopen Function In Python
Jonathan Bowman HackerNoon profile picture
Jonathan Bowman

Jonathan Bowman

@bowmanjd

Constantly learning software development, Python, Linux, containers, and a little Rust. Thinks regex is fun.

About @bowmanjd
LEARN MORE ABOUT @BOWMANJD'S
EXPERTISE AND PLACE ON THE INTERNET.
L O A D I N G
. . . comments & more!

About Author

Jonathan Bowman HackerNoon profile picture
Jonathan Bowman@bowmanjd
Constantly learning software development, Python, Linux, containers, and a little Rust. Thinks regex is fun.

TOPICS

THIS ARTICLE WAS FEATURED IN...

Permanent on Arweave
Read on Terminal Reader
Read this story in a terminal
 Terminal
Read this story w/o Javascript
Read this story w/o Javascript
 Lite