O'Reilly logo

Python Requests Essentials by Bala Subrahmanyam Varanasi, Rakesh Vidya Chandra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Different types of request contents

Requests has the facility to deal with different types of Request contents like binary response content, JSON response content, and raw response content. To give a clear picture on different types of response content, we listed the details. The examples used here are developed using Python 2.7.x.

Custom headers

We can send custom headers with a request. For that, we just need to create a dictionary with our headers and pass the headers parameter in the get, or post method. In the dictionary, key is the name of the header and the value is, well, the value of the pair. Let us pass an HTTP header to a request:

>>> import json
>>> url = 'https://api.github.com/some/endpoint'
>>>  payload = {'some': 'data'}
>>> headers ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required