ItSolutionStuff.com

Python Post Request with Basic Authentication Example

By Hardik Savani • October 30, 2023
Python

Hello,

If you need to see example of python post request with basic authentication. we will help you to give example of python http requests basic auth. We will look at example of python request with username and password. I would like to show you python request with basic auth. So, let's follow few step to create example of python requests with basic authorization.

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.

You can use these examples with python3 (Python 3) version.

let's see below simple example with output:

Example 1:

main.py

import requests
import json
  
url = 'https://reqres.in/api/users'
  
params = {'name': 'Hardik', '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:

I hope it can help you...

Tags: Python
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

Python Get File Extension from Filename Example

Read Now →

Python Create Zip Archive from Directory Example

Read Now →

How to Check if Today is Saturday or not in Python?

Read Now →

How to Check if Today is Thursday or not in Python?

Read Now →

How to Add Minutes to DateTime in Python?

Read Now →

Python PATCH Request with Parameters Example

Read Now →

Python DELETE Request Example Tutorial

Read Now →

Python PUT Request with Parameters Example

Read Now →

Python POST Request with Parameters Example

Read Now →

Python GET Request with Parameters Example

Read Now →

How to Get Current Hour in Python?

Read Now →