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:
- Get Last 2 Digits of Number in Python Tutorial Example
- How to Sum of First and Last Digit of Number in Python?
- How to Get First and Last Digit of Number in Python?
- Get the Last Digit of Number in Python Tutorial Example
- Get the First Digit of Number in Python Tutorial Example
- How to Remove All Decimals from Number in Python?
- How to Convert String to Float with 2 Decimal Places in Python?
- How to Format Number to 2 Decimal Places in Python?