
- Requests Tutorial
- Requests - Home
- Requests - Overview
- Requests - Environment Setup
- Requests - How Http Requests Work?
- Requests - Working with Requests
- Handling Response for HTTP Requests
- Requests - HTTP Requests Headers
- Requests - Handling GET Requests
- Handling POST, PUT, PATCH & DELETE Requests
- Requests - File Upload
- Requests - Working with Cookies
- Requests - Working with Errors
- Requests - Handling Timeouts
- Requests - Handling Redirection
- Requests - Handling History
- Requests - Handling Sessions
- Requests - SSL Certification
- Requests - Authentication
- Requests - Event Hooks
- Requests - Proxy
- Requests - Web Scraping using Requests
- Requests Useful Resources
- Requests - Quick Guide
- Requests - Useful Resources
- Requests - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Requests - Overview
Requests is a HTTP library that provides easy functionality to deal with http request/response in your web application. The library is developed in python.
The official website of Python Requests which is available at https://2.python-requests.org/en/master/ defines Requests as follows −
Requests is an elegant and simple HTTP library for Python, built for human beings.
Features of Requests
The features of Requests are discussed below −
Request
The python requests library has easy to use methods available to handle Http request. Passing of parameters and handling the request type like GET, POST, PUT, DELETE, etc. is very easy.
Response
You can get the response in the format you need and the supported ones are text format, binary response, json response, and raw response.
Headers
The library allows you to read, update or send new headers as per your requirements.
Timeouts
Timeouts can be easily added to the URL you are requesting using python requests library. It so happens that you are using a third-party URL and waiting for a response.
It is always a good practice to give a timeout on the URL as we might want the URL to respond within that timeout with a response or an error that is coming because of timeout. Not doing so can cause either to wait on that request indefinitely.
Error handling
The requests module gives support for error handling and some of which are Connection Error, Timeout errors, TooManyRedirects, Response.raise_for_status errors, etc.
Cookies
The library allows you to read, write and update for the requested URL.
Sessions
To maintain the data, you require between requests you need sessions. So, if the same host is called again and again you can re-use the TCP connection which in turn will improve the performance.
SSL certificates
SSL certificate is a security feature that comes with secure urls. When you use Requests, it also verifies SSL certificates for the https URL given. SSL Verification is enabled by default in the requests library and will throw an error if the certificate is not present.
Authentication
HTTP authentication is on the server-side asking for some authentication information like username, password when the client requests a URL. This is an additional security for the request and the response being exchanged between the client and the server.
Advantages of using Python Requests Library
Following are the advantages of using Python Requests Library −
- Easy to use and fetch the data from the URL given.
- Requests library can be used to scrape the data from the website.
- Using requests, you can get, post, delete, update the data for the URL given.
- The handling of cookies and session is very easy.
- The security is also taken care of the help of authentication module support.