I have a headless Pi Zero that's connected to the internet through the USB ethernet gadget from my computer.
Through SSH (with Powershell), I'm running a Python3 script on the Pi which will start an HTTP server (using Python's native http.server and socketserver library). The Pi will put a local HTML file
index.html that's in its SD card online for me to view from my PC by going to
index.html file is supposed to contain some text and an image. When I run the server on my Pi and view the
index.html file through
raspberrypi.local:8000, I can see the text just fine. However, the image doesn't appear (just a broken image placeholder).
Here is the code for my
<html> <head> <title>Pi Cam</title> </head> <body style="background-color:#868167;"></body> <body> <h1 style="font-family:Calibri" style="text-align:center">Here is a photo of a dog!</h1> <img src="/focustest.jpg"> </body> </html>
I'm not sure why I can't view the image. The image is located in the same directory as the index file, but it's not working. Does anyone know what's going on?
My Python code is:
import picamera import logging from http import server import _thread from ctypes import * import os import http.server import socketserver import time camera = picamera.PiCamera() camera.start_preview() time.sleep(1) camera.capture('focustest.jpg') time.sleep(1) camera.stop_preview() camera.close() print('Image captured. Starting server... ') print('') #============================================================================== try: PORT = 8000 class MyHttpRequestHandler(http.server.SimpleHTTPRequestHandler): def do_GET(self): self.path = 'index.html' return http.server.SimpleHTTPRequestHandler.do_GET(self) Handler = MyHttpRequestHandler socketserver.TCPServer.allow_reuse_address = True with socketserver.TCPServer(("", PORT), Handler) as httpd: print("HTTP Server Serving at Port", PORT) httpd.serve_forever() except KeyboardInterrupt: httpd.shutdown() httpd.socket.close() print('Server shut down.')