.post()
The .post()
method sends a POST
request to a web server and it returns a response object.
Syntax
import requests
requests.post("url", **kwargs)
**kwargs
are any number of dictionary items (named arguments) that are passed in as parameters. Many different named parameters can be passed into a POST
request. For example, they can be used to include cookies in the request, set proxies, set headers, or set a page timeout.
Example
The .post()
method can take in various parameters. These parameters allow a user to communicate additional information to the web server, such as data or JSON, to send in the request body to create or update a resource.
import requestsdata = {"my_key": "my_value"}response = requests.post("https://codecademy.com", data=data)print(f"{response.status_code}: {response.reason}")
This will print the following output:
200: OK
Codebyte Example
The response object returned by the .post()
method contains various types of data, such as the webpage text, status code, and the reason for that response.
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Python on Codecademy
- Skill path
Analyze Data with Python
Learn to analyze and visualize data using Python and statistics.Includes 8 CoursesWith CertificateIntermediate13 hours - Course
Learn Python 3
Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.With CertificateBeginner Friendly23 hours