python
Send post request with data and headers Python requests
You can send HTTP requests using the python package requests. Also, you can send form data, raw data, and headers in the HTTP request.
import requests
raw_json_data = { "user_name": "hello", "password": "password1" }
data = { "first_name": "hello", "last_name": "world" }
headers = { 'Authorization': 'Bearer token_value_here' }
response = requests.post('https://path/to/api/url/endpoint', headers = headers, data = data, json=raw_json_data)
print(response.status) #prints the status of request
print(response.content) #prints the content
print(response.json()) #json formatted data if response returns any
In the code snippet, we are sending a request using the python-requests package. You can install the requests package in your python project using the below command
pip install requests
Was this helpful?
Similar Posts
- Django send post request with different field than primary key.
- [Python] Get nodeid, module, function name using Pytest request built-in fixture
- Column and data types in Sqlalchemy
- To get url param details from get request in Django
- [Python] Save (write) data to file
- Read JSON data in python
- Create pandas DataFrame and add columns and rows to it