Post Request with Basic Authentication in Python

23-Sep-2022

.

Admin

Post Request with Basic Authentication in Python

Hi Dev,

Now, let's see article of Post Request with Basic Authentication in Python. you can see Python Make Request with Basic Auth. This article goes in detailed on Python Requests with Basic Authorization. step by step explain Python Request with Basic Auth.

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

let's see below simple example with output:

Example 1:


main.py

import requests

import json

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

params = {'name': 'Vivek Thummar', 'job': 'Developer'}

username = "enterUsername"

password = "enterPassword"

response = requests.post(url, auth=(username, password), json=params)

data = response.json()

print(data)

Output:

Example 2:

main.py

import requests

import json

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

header = {"Authorization" : "Basic cG9zdG1hbjpwYXNzd29yZA=="}

response = requests.get(url, headers=header)

data = response.json()

print(data)

Output:

#Python