Network Programming Python – HTTP Clients
The request from the client in HTTP protocol reaches the server and fetches some data assuming it to be a valid request. This response from the server can be analyzed by using various methods provided by the requests module. Some of the ways below provide information about the response sent from the server to the Python program running on the client-side :
Getting initial Response
The get() method is used to get the basic information of the resources used at the server-side. This function fetches the data from the server and returns as a response object which can be printed in a simple text format.
The session() method returns the session object which provides certain parameters to manipulate the requests. It can also manipulate cookies for all the requests initiated from the session object. If a large amount of requests are made to a single host then, the associated TCP connection is recalled.
If some error is raised in processing the request to the server, the exception is raised by the program which can be handled using the timeout attribute, which defines the time value until the program waits and after that, it raises the timeout error.
requests.exceptions.RequestException as e:
HTTPSConnectionPool(host=’www.geeksforgeeks.org’, port=443): Max retries exceeded with url: / (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x0000018CFDAD83C8>, ‘Connection to www.geeksforgeeks.org timed out. (connect timeout=1e-06)’))
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses
are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!