title: HTML webside URL change should work with PYTHON script on Raspberry Pi 3
body: <p>I tried to run a Python script to controll my led's via GPIO. With a HTML interface i want to communicate with the script. On the Website are only buttons which changes the url for example to http:local.host:/set/mode/pin/strip/color. For each button different numbers.</p>
  
  <p>Im not able to run the script on a webserver. i tried it with lighttpd but failed.
  I was able to connect to my html file but when it changes the url there is the 404 error. (of course, it gets nothing back to load)</p>
  
  <p>I tried it with the module bottle (little webserver) but its not working either.
  (with @route ("/set/mode/pin/strip/color") )
  I already had an old bad wrote script and it worked fine with bottle but now i upgraded and now it wont work. btw bottle was not reliable on long sight, it crashed after a while.</p>
  
  <p>From my HTML interfaces these are some Buttons which changes the url. </p>
  
  <pre><code>&lt;table&gt;
  &lt;tr&gt;
      &lt;td&gt;
  &lt;input type=button onClick="location.href='/set/0///'" class="button head black" value="Reset"&gt;&lt;/td&gt;
          &lt;td&gt;
  &lt;input type=button onClick="location.href='/set/3///0'" class="button head red" value="Rot"&gt;&lt;/td&gt;   
      &lt;td&gt;
  &lt;input type=button onClick="location.href='/set/3///1'" class="button head green" value="Grun"&gt;&lt;/td&gt;
      &lt;td&gt;
  &lt;input type=button onClick="location.href='/set/3///2'" class="button head blue" value="Blau"&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
      &lt;td&gt;
  &lt;input type=button onClick="location.href='/set/2//0/'" class="button black" value="Strip 0"&gt;&lt;/td&gt;
          &lt;td&gt;
  &lt;input type=button onClick="location.href='/set/1/0//'" class="button borderred" value="Rot"&gt;&lt;/td&gt;
          &lt;td&gt;
  &lt;input type=button onClick="location.href='/set/1/1//'" class="button bordergreen" value="Grun"&gt;&lt;/td&gt;
      &lt;td&gt;
  &lt;input type=button onClick="location.href='/set/1/2//'"  class="button borderblue" value="Blau"&gt;&lt;/td&gt;
  &lt;/tr&gt;   &lt;tr&gt;
      &lt;td&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>My Python script. After i failed several times i tried sth with urlopen but i m not sure if i undertood it right.
  You dont need to check the full code. the problem is propably in main() and or also in webside()</p>
  
  <pre><code>#!/usr/bin/python2
  try:
      from urllib.request import urlopen
  except ImportError:
      from urllib2 import urlopen
  import RPi.GPIO as GPIO
  #from bottle import route, run
  
  #@route ("/led.html")
  def webside():
      with open("led.html", "r") as file:
          content = file.read()
          print("return sth")
      return content
  
  class Processing():
      state_pin = [28]
  
      def output_check(self, pin):
          settings = self.get_settings_file()
          for pos in range(len(settings)):
              if settings[pos] == pin:
                  return True
          return False
  
      def set_state_pin(self, pin, value):
          self.state_pin[pin] = value
  
      def get_state_pin(self, pin):
          return self.state_pin[pin]
  
      def create_string(self, input):
          new_string = ""
          for text in input:
              new_string += text + ","
          new_string[-1] = ""
          return new_string
  
      def get_settings_file(self):
          try:
              with open("gpio.txt", "r") as file:
                  settings = file.read().split(",")
                  return settings
          except OSError:
              with open("gpio.txt", "w") as file:
                  file.write(self.create_string(self.default_settings()))
                  print(file + " created")
  
      def add_pin_file(self, mode, pin):
          with open("gpio.txt", "w+") as file:
              settings = file.read().split(",")
              if settings != pin:
                  settings += pin
              file.write(self.create_string(settings))
  
      def del_pin_file(self, mode, pin):
          with open("gpio.txt", "w+") as file:
              settings = file.read().split(",")
              for pos in range(len(settings)):
                  if settings[pos] == pin:
                      del settings[pos]
                      break
              file.write(self.create_string(settings))
  
      def default_settings(self):
          return [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,17,18,19,20,21,22,23,24,25,26,27]  # all pins
  
  
      def get_strip(self, pos):
          strips = [[1,2,3],           # strip 0
                  [4,5,6],            # strip 1
                  [7,8,9],            # ...
                  [10,11,12],
                  [],
                  [],
                  [],
                  [],
                  ]
          return strips[pos]
  
  
      def get_color(self, pos):
          colours = [[1,4,7,10,13,17],  # red
                  [],                 # green
                  []                  # blue
                  ]
          return colours[pos]
  
  
  #@route ("/set/&lt;mode&gt;/&lt;pin&gt;/&lt;strip&gt;/&lt;color&gt;")
  def set(mode, pin, strip, color):
      print("set sth")
  #    urlopen("http://192.168.0.32/set/{}/{}/{}/{}".format(mode, pin, strip, color)).read()
      process = Processing()
  
      # reset/set
      if mode == 0:
          for pins in process.get_settings_file():
              GPIO.output(pins, mode)
              process.set_state_pin(pins, mode)
  
      # single pin
      if mode == 1:
          if process.output_check(pin):
              if process.get_state_pin(pin):
                  GPIO.output(pin, 0)
                  process.set_state_pin(pin, 0)
              else:
                  GPIO.output(pin, 1)
                  process.set_state_pin(pin, 1)
  
      # one strip
      if mode == 2:
          pins = process.get_strip(strip)
          value = 1
  
          for pin in pins:
              if process.get_state_pin(pin):
                  value = 0
  
          for pin in pins:
              if process.output_check(pin):
                  GPIO.output(pin, value)
                  process.set_state_pin(pin, value)
  
      # one color
      if mode == 3:
          pins = process.get_color(color)
          value = 1
  
          for pin in pins:
              if process.get_state_pin(pin):
                  value = 0
  
          for pin in pins:
              if process.output_check(pin):
                  GPIO.output(pin, value)
                  process.set_state_pin(pin, value)
  
      return webside()
  
  def main():
      GPIO.setwarnings(False)
      GPIO.setmode(GPIO.BCM)
      settings = Processing().default_settings()
      for pin in settings:
          GPIO.setup(pin, GPIO.OUT)
      try:
          mode = 0
          pin = 0
          strip = 0
          color = 0
          var = [0,0,0,0]
          while True:
              urlopen("http://192.168.0.32/set/{}/{}/{}/{}".format(mode, pin, strip, color)).read()
              if mode != var[0] or pin != var[1] or strip != var[2] or color != var[3]:
                  var[0] = mode
                  var[1] = pin
                  var[2] = strip
                  var[3] = color
                  set(mode, pin, strip, color)
      except KeyboardInterrupt:
          GPIO.cleanup()
  
  #run(host="0.0.0.0",port=88)
  
  if __name__ == "__main__":
      main()
  </code></pre>
  
  <p>the error i get from the commandline:
  <a href="https://i.stack.imgur.com/YkawQ.png" rel="nofollow noreferrer">error_code_raspi</a></p>
  
  <p>Its my first Question in this community. Hope i did everything right.
  Can somebody give me hints ? Would be amazing i want to use my LED's :)
  Thanks in advance.</p>