April 14, 2019

Printing and debugging Python HTTP requests

Using Python Requests for humans it is a breeze to send requests. It can be tricky to make sure your requests are correct though!

Sending a GET request

Sending a POST request:

This is magic and works great. But when you get a 400 Bad Request you know you need to debug it! Enter the stage, bare and prepared requests!

Basically you create a bare request and “prepare” it. You can then pretty print it with headers and all the goodness. It looks something like this:

Output will be similar to:

Great stuff. Love Python.