Post Request with pem File in Python Code Example

04-Nov-2022

.

Admin

Post Request with pem File in Python Code Example

Hi Dev,

Today, Post Request with pem File in Python Code Example is our main topic. This article will give you simple example of How to Send Http Request with Client Certificate. I explained simply about Python Requests Post pem File. this example will help you Python Post Request with pem Example. Let's get started with Python Http Request with Cert.

Here, we will use requests library to all POST HTTP Request with pem file or certificate file and get JSON response in python program. In this example i will create pem file as client certificate and send http request with client certificate. 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:


main.py

import requests

import json

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

headers = {

'Accept' : 'application/json',

'Content-Type' : 'application/json'

}

param = {

"name": "Hardik",

"job": "Developer"

}

response = requests.post(url, json=param, headers=headers, verify='/path/cert.pem')

data = response.json()

print(data)

Mame sure, you have to put "/path/cert.pem" certificate file on path.

Output :

#Python