Python 3: simple HTTP Request with the Socket module

GeeXLab and Python 3 - simple HTTP request with the socket module

Let’s look at one of the important modules that is included in the Python standard library: the socket module.

This module provides access to the BSD socket interface. It is available on all modern Unix systems, Windows, MacOS, and probably additional platforms.

The reference guide of the socket module is available here: socket — Low-level networking interface.

I prepared a demo that shows a simple use case of the socket module: how to send an HTTP GET request to get the content of a webpage.

The demo requires GeeXLab 0.27.2+. Download the demopack, unzip it where you want and load into GeeXLab (drag an drop) the socket/01-socket-http-request/main.xml file.

By default the target is But you can change it to any other target. Then click on the Send HTTP GET request - Port 80 button. This operation will send the following request to

GET / HTTP/1.1\r\\r\n\r\n

And you will receive the following reply from Google server:

GeeXLab and Python 3 - simple HTTP request with the socket module

Here is the Python 3 code that executes the HTTP GET request (line 84 in the demo file):

target_host = "" 
target_port = 80  # create a socket object 
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)  
# connect the client 
# send some data 
request = "GET / HTTP/1.1\r\nHost:%s\r\n\r\n" % target_host
# receive some data 
response = client.recv(4096)  
http_response = repr(response)
http_response_len = len(http_response)
#display the response
gh_imgui.text("[RECV] - length: %d" % http_response_len)

In the demo, the target_host variable has been filled up by the input text (ImGui function).

One thought on “Python 3: simple HTTP Request with the Socket module”

Leave a Comment

Your email address will not be published. Required fields are marked *