Network Programming Python - HTTP Clients Last Updated : 25 Oct, 2020 Comments Improve Suggest changes Like Article Like Report 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. Python3 # Import libraries import requests # Sending Request req = requests.get('https://www.geeksforgeeks.org/') # Show results print(req.text[:2000]) Output: Getting session-info 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. Python3 # Import Libraries import requests # Creating Session s = requests.Session() s.get('http://httpbin.org/cookies/set/sessioncookie/419735271') # Getting Response r = s.get('http://httpbin.org/cookies') # Show Response print(r.text) Output: { "cookies": { "sessioncookie": "419735271" } } Error Handling 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. Python3 # Import Libraries import requests # Error Handling try: # Creating Request req = requests.get('https://www.geeksforgeeks.org/', timeout=0.000001) except requests.exceptions.RequestException as e: # Raising Error raise SystemExit(e) Output: 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)')) Comment More infoAdvertise with us Next Article Network Programming Python - HTTP Clients J jeeteshgavande30 Follow Improve Article Tags : Technical Scripter Python Programming Language Python-Networking Practice Tags : python Similar Reads Network Programming Python - HTTP Server HTTP Web Server is simply a process which runs on a machine and listens for incoming HTTP Requests by a specific IP and Port number, and then sends back a response for the request. Python has a built-in webserver provided by its standard library, can be called for simple client-server communication. 3 min read Network Programming Python - HTTP Requests HTTP stands for HyperText Transfer Protocol, which works on the client-server machine. In most cases, the web browser acts as the client, and the computer which hosts the website acts as a server. Python provides the requests module to play with HTTP requests. The requests module plays a major role 2 min read CGI Programming in Python What is CGI? Common Gateway Interface (also known as CGI) is not a kind of language but just a specification(set of rules) that helps to establish a dynamic interaction between a web application and the browser (or the client application). The CGI programs make possible communication between client 5 min read Socket Programming in Python Socket programming is a way of connecting two nodes on a network to communicate with each other. One socket(node) listens on a particular port at an IP, while the other socket reaches out to the other to form a connection. The server forms the listener socket while the client reaches out to the serv 6 min read Tornado- HTTP servers and clients Tornado is a Python web framework and a library for async networks. It is meant for non-blocking, highly effective apps. Tornado has become popular because it can handle large numbers of simultaneous connections easily. In this article, we will explain Tornado HTTP servers and clients. What are HTTP 4 min read Like