Introduction:

While socket programming with Python, I realized that I was getting some strange HTTP Status codes, but I had no idea what they actually meant.

I googled it and found instant results from a couple of cool websites, but I was wondering if can web harvest HTTP Status code information from a website and wrap it in a function which can query these statuses to add more verbosity to my web requests.

On top of that, once I have the HTTP Status codes and their description in a CSV, JSON or XML format, I can repurpose this data in any program/script as desired which is obviously way better than Googling it each and every time when troubleshooting such errors.

Making it work:

First get information for all the HTTP status code, but where to get it? I figured out many websites that have such information like https://httpstatuses.com/ and if you inspect the source code of the website you can easily web harvest this data Similarly, more detailed description of these HTTP status codes can be accessed by suffixing the URL with the status code like in the following image So I wrote a small PowerShell script (below) to web request and capture this information from the website and export the result to CSV file.

Once you have the information in CSV format you require this file to be accessible so that it can be easily downloaded over the internet from anywhere in the world.

In order to achieve this, I copy-pasted/committed it to my Github repository from where it could be downloaded to any machine with access to the internet since the file is Public. Write a Powershell function that can Web request above mentioned public Github gist URL and downloads the contents of the CSV file.

and the contents of the CSV file. Filter out the HTTP status code you’re trying to search from the content and display its description Following is the PowerShell function to get above done

When the Powershell function runs for the first time, it creates a local copy of content in a File at a static location, which could be accessed to get HTTP status codes information locally for all Future function calls by avoiding the Web request which is slower.

Took care of point-4 in my PowerShell function like in the screenshot below



Running the Function:

You can run the function on demand like in the below screenshot.

NOTE – The first call to the function would be slow, but from the next call you have a local copy of the CSV file on your machine, which can be queried comparatively much faster to web requests.

Hope you’ll find the script useful, please don’t forget to share this script with your friends and colleagues.

Thanks for reading, and happy Deepawali to you and your Family! 🙂