Python Post Request with Json File Example
Hey,
This post is focused on python post request with json file. This tutorial will give you simple example of python request with json body. This article goes in detailed on python post request with json file. it's simple example of python request json file.
Here, we will use requests library to all POST HTTP Request with json file as parameters and get JSON response in python program. In this example i will create parameters.json file and take json parameters from that file. 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:
main.py
import requests import json url = 'https://reqres.in/api/users' headers = { 'Accept' : 'application/json', 'Content-Type' : 'application/json' } contents = open('parameters.json', 'rb').read() response = requests.post(url, data=contents, headers=headers) data = response.json() print(data)
parameters.json
{ "name": "Hardik", "job": "Developer" }
Output:
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Python Post Request with Bearer Token Example
- Python Copy File From one Directory to Another Example
- Python Create Zip Archive from Directory Example
- Python List All Dates Between Two Dates Example
- How to Compare Two Dates in Python?
- Python PATCH Request with Parameters Example
- Python DELETE Request Example Tutorial
- Python PUT Request with Parameters Example
- Python POST Request with Parameters Example
- Python GET Request with Parameters Example