Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: need more than 0 values to unpack #55

Open
RasecMP opened this issue Jul 19, 2023 · 1 comment
Open

Error: need more than 0 values to unpack #55

RasecMP opened this issue Jul 19, 2023 · 1 comment

Comments

@RasecMP
Copy link

RasecMP commented Jul 19, 2023

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()

@tibor8472
Copy link

tibor8472 commented Oct 5, 2023

Refactoring _async def parse_headers 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants