Open RasecMP opened 1 year ago
Refactoring _async def _parseheaders in server.py worked for my project:
async def _parse_headers(reader):
headers = {}
while True:
header_line = await reader.readline()
if header_line == b"\r\n":
break
try:
name, value = header_line.decode().strip().split(": ", 1)
except ValueError as ex :
return headers
headers[name.lower()] = value
return headers
Do not forget to adjust intent because it is 2 whitespaces in server.py.
I get the error mentioned in the title after a while running main.py with the following code:
import machine import time from phew import server, connect_to_wifi from phew.template import render_template
machine.Pin(13, machine.Pin.IN) machine.Pin(18, machine.Pin.IN)
connect_to_wifi("SSID", "PASSWORD")
@server.route("/passagem", methods=["GET", "POST"]) def passagem(request):
post = request.data.get("value", None) password = request.form.get("password", None)
if(post=="door1"): machine.Pin(18, machine.Pin.OUT) time.sleep(1) machine.Pin(18, machine.Pin.IN)
elif(post=="door2"): machine.Pin(13, machine.Pin.OUT) time.sleep(1) machine.Pin(13, machine.Pin.IN)
if(password == "password"): return render_template("index.html"), 200
else: return render_template("login.html"), 200
@server.route("/favicon.png", methods=["GET"]) def favicon(request): return render_template("favicon.png"), 200
@server.catchall() def catchall(request): return "Not found", 404
server.run()