Python Post Request with pem File Tutorial

Published On: 19/10/2022 | Category: Python


Hi Guys,

In this tutorial, you will learn python post request with pem file. I explained simply about python post request with pem file. We will use python request pem file. This article will give you simple example of python request with pem body.

In this case, we'll make use of the requests module to execute all POST HTTP Requests with a PEM or certificate file and receive a JSON answer in a Python programme. In this example, I'll construct a client certificate in a pem file and send an HTTP request accompanied by that certificate. 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.

So let's see bellow example:

Example:

main.py
import requests
import json
  
url = 'https://reqres.in/api/users'
  
headers = {
             'Accept' : 'application/json', 
             'Content-Type' : 'application/json'
             }
  
param = {
    "name": "Sonagra", 
    "job": "Developer"
}
  
response = requests.post(url, json=param, headers=headers, verify='/path/cert.pem')
  
data = response.json()
  
print(data)
Output
{
    'name': 'Bhavesh', 
    'job': 'Developer', 
    'id': '409', 
    'createdAt': '2022-10-19T04:27:04.623Z'
}

It will help you....

Happy Pythonic Coding!