sya
sya

Reputation: 45

Run Python3 Web server program when Raspberry Pi Reboot

I want to ask. How to run python3 web server automatically when Raspberry Pi Reboot/ON . Plus Im using Wlan0 as my internet connection.

When I run normally in Thonny Python, it can be run.

However to make it run automatic when Raspberry Pi reboot is error [erno 99]: Cannot Assign Request Address

I trying run it in Crontab and etc/local.rc but the result is same. Error happen

This is my code:

from http.server import BaseHTTPRequestHandler, HTTPServer

class RequestHandler_httpd(BaseHTTPRequestHandler):
  def do_GET(self):
    messagetosend = bytes('Hello World!',"utf")
    self.send_response(200)
    self.send_header('Content-Type', 'text/plain')
    self.send_header('Content-Length', len(messagetosend))
    self.end_headers()
    self.wfile.write(messagetosend)
    print(self.requestline)
    return


server_address_httpd = ('172.X.X.X',8080)
httpd = HTTPServer(server_address_httpd, RequestHandler_httpd)
print('Starting Server')
httpd.serve_forever()

Upvotes: 0

Views: 261

Answers (1)

Pranav Kumar
Pranav Kumar

Reputation: 81

I don't know about local.rc, but using crontab -e has worked perfectly for me to start webservers like these on startup on raspberrypis.

This is the tutorial i followed, pretty straight forward. https://www.youtube.com/watch?v=zRXauWUumSI&t=64s

Upvotes: 1

Related Questions