I'm practising CGI scripts with an Apache 2.4 localhost running on my Raspberry Pi 3B. Essentially I have an HTML form that sends a string and an RGB value to a Python CGI file, which is then supposed to make the LED matrix on the sense hat display the message with that RGB value.
The issue is that when I call sense = SenseHat(), I get the following error:
Traceback (most recent call last): File "/var/www/html/cgi-bin/test.py", line 23, in SenseHat().show_message(text, text_colour=[red, green, blue]) File "/usr/lib/python3/dist-packages/sense_hat/sense_hat.py", line 92, in __init__ self._stick = SenseStick() File "/usr/lib/python3/dist-packages/sense_hat/stick.py", line 57, in __init__ self._stick_file = io.open(self._stick_device(), 'rb', buffering=0) File "/usr/lib/python3/dist-packages/sense_hat/stick.py", line 83, in _stick_device if f.read().strip() == self.SENSE_HAT_EVDEV_NAME: File "/usr/lib/python3.4/encodings/ascii.py", line 26, in decode return codecs.ascii_decode(input, self.errors)[0] UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 19: ordinal not in range(128)
I can successfully send commands to the sense hat using python from that directory and all other directories. I tried building a module that would handle pushing the information to the sense_hat separately but that threw the same error.
For completeness, I'll post the HTML and Python in its completeness below.
#!/usr/bin/python3.4
# -*- coding: UTF-8 -*-# enable debugging
from sense_hat import SenseHat
import cgi
import traceback
form = cgi.FieldStorage()
print("Content-type:text/html\r\n\r\n")
try:
text = form.getvalue("text")
red = int(form.getvalue("red"))
green = int(form.getvalue("green"))
blue = int(form.getvalue("blue"))
if len(text) in range(0, 51) and red in range(0,256) and green in range(0,256) and blue in range(0,256):
#this if statement checks that the values for R, G and B are all valid, and that the text
#length is <= 50 characters
print("Now running your request<br>")
SenseHat().show_message(text, text_colour=[red, green, blue])
else:
raise SyntaxError
except:
print('<h1 style="color:red;">ERROR!</h1>')
print(traceback.format_exc())
Hi all,
I'm practising CGI scripts with an Apache 2.4 localhost running on my Raspberry Pi 3B. Essentially I have an HTML form that sends a string and an RGB value to a Python CGI file, which is then supposed to make the LED matrix on the sense hat display the message with that RGB value.
The issue is that when I call sense = SenseHat(), I get the following error:
I can successfully send commands to the sense hat using python from that directory and all other directories. I tried building a module that would handle pushing the information to the sense_hat separately but that threw the same error.
For completeness, I'll post the HTML and Python in its completeness below.
HTML:
and the Python: