Coolq B Coolq B - 1 year ago 48
Python Question

Python HTTP server, can't use images

What I've done:
I've created a small HTTP server python, using no modules but socket. It manages to start, load HTML and then send it out,

so you can see the HTML file in your browser.

What I'm using:
I'm using Python 3.5.1, I'm also using Socket.

The problem:
Images do not show on the web browser.

Here is the code I have put together:

import socket

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

HOST = ''
PORT = 8888

asked_url = []

s.bind((HOST, PORT))


while True:
conn, addr = s.accept()

request = conn.recv(1024)

html_file = open("page.html", 'rb')
http_response =
print("Couldn't send any data! Passing...")

Here is also the HTML code for the page, However it doesn't seem to be the problem:

<script src=""></script>
<div class="server-status">
My awesome server is currently <span class="server-online"></span>!
MinecraftAPI.getServerStatus('SERVER HERE', {
port: 25565 // optional, only if you need a custom port
}, function (err, status) {
if (err) {
return document.querySelector('.server-status').innerHTML = 'Error loading status';

// you can change these to your own message!
document.querySelector('.server-online').innerHTML = ? 'up' : 'down';

<img src="test.png" alt="Test Image" style="width:304px;height:228px;">

What the HTML code does:
Shows text and an image.

If you need more detail just ask.


Where is test.png located? Looks like your HTML is having an issue finding the file. I ran your code locally and was able to see an image when I changed to image tag to source an image from a url.

I checked chrome dev tools first and noticed the image tag rendered fine.

I changed the image tag to (random image from google image search):

`<img src="" alt="Test Image">`

And it showed up fine.