Python Requests Module
Functions for Making Requests:
requests.request()
: Sends a request to a specified URL with customizable parameters.requests.get()
: Sends a GET request to the specified URL.requests.post
()
: Sends a POST request to the specified URL with data in the request body.requests.put()
: Sends a PUT request to the specified URL.requests.delete()
: Sends a DELETE request to the specified URL.requests.head()
: Sends a HEAD request to the specified URL.requests.options()
: Sends an OPTIONS request to the specified URL.requests.patch()
: Sends a PATCH request to the specified URL.
Utility Functions:
requests.session()
: Creates a session object for managing and persisting parameters across multiple requests.requests.cookies()
: Represents the cookies sent in the request.requests.utils()
: Utility functions for working with URLs and query strings.requests.exceptions
: Module containing exceptions raised byrequests
.requests.adapters
: Module containing classes for managing connection pools and retries.requests.models()
: Contains models used byrequests
, likeResponse
,Request
, etc.requests.hooks
: Module to register hooks for certain events in the request lifecycle.
Classes and Objects:
requests.Response()
: Represents a response from an HTTP request, with properties likestatus_code
,text
,content
, etc.requests.Request()
: Represents a HTTP request to be sent, allowing for fine-grained control.requests.Session()
: Represents a session for sending requests, maintaining settings, and managing cookies.requests.PreparedRequest()
: Represents a pre-prepared request object, ready to be sent viaSession.send()
.
Request and Response Properties:
response.status_code
: Property that returns the HTTP status code of the response.response.text
: Property that returns the response content in Unicode.response.content
: Property that returns the response content in bytes.response.json()
: Method that parses the response content as JSON.request.url
: Property that returns the URL of the request.request.headers
: Property containing the request headers.
These functions, classes, and properties cover the complete functionality of the requests
module in Python, allowing for versatile HTTP request handling, response processing, and efficient management of sessions and connections.