Skip to content

All topics  /  Python

Post Request with Bearer Token Example in Python

Python

Sep 22, 2022

Hi Dev,

I am going to show you example of Post Request with Bearer Token Example in Python. if you have question about Extract Bearer Token From Header Python then I will give simple example with solution. I explained simply step by step Python Requests Header Bearer Token. if you want to see example of Python Get Request Header Bearer Token then you are a right place.

Here, we will use requests library to all POST HTTP Request with header bearer token and get JSON response in python program. I will give you a very simple example to call POST Request with body parameters in python.

so let's see following examples with output:

Example


main.py

import requests

  
url = 'https://reqres.in/api/users'

  
params = dict(
    name="Vivek Thummar",
    job="Developer",
)

  
authToken = "abcd123...."
headers = {
        'Authorization': 'Bearer ' + authToken,
        'Content-Type': 'application/json'
    }

  
response = requests.post(url, params, headers)

  
data = response.json()

  
print(data)

Output: