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

Server module - Response isnt always created, leading to an error (NoneType) #12

Open
kevinmcaleer opened this issue Sep 26, 2022 · 1 comment

Comments

@kevinmcaleer
Copy link

There is a bug where the Server Module is checking all the scenarios, and if response is still set to None, the line writing out what the response.status is will throw an error (Line 277 in server.py)

# write status line
  status_message = status_message_map.get(**response.status**, "Unknown")

either need to check if response is still None (if response is not None) or set it to a default value.

There is another line further down 282 that will also fail - for key, value in response.headers.items():

@Nikorasu
Copy link

Nikorasu commented Apr 5, 2023

I've been trying to track down an odd bug, that tends to cause my pico's wifi interface to occasionally hang/crash until a full machine.reset(), a few times a day..

Once I add that if response is not None to the lines you suggest, the error that usually lead to the interface crash, doesn't seem to do that anymore. (Or at least, I think it's related to what's causing it: [error / 117kB] need more than 0 values to unpack)
So far so good tho, saw the error once, but the device hasn't crashed again yet, so hopefully this was a good enough fix!

Here's more specifically what I modified, basically just indenting from line 276 to 285, if anyone else is having this issue:

  if response is not None:
    # write status line
    status_message = status_message_map.get(response.status, "Unknown")
    writer.write(f"HTTP/1.1 {response.status} {status_message}\r\n".encode("ascii"))

    # write headers
    for key, value in response.headers.items():
      writer.write(f"{key}: {value}\r\n".encode("ascii"))

    # blank line to denote end of headers
    writer.write("\r\n".encode("ascii"))

Edit: It seems to have made a slight improvement, but there's still a crash that happens somewhere.. Also testing a possible fix to the _parse_json_body function, if it's sent an invalid json request..

Edit2: nvm, that previous edit doesn't really seem to matter one way or the other. What did improve things for me, was adding a lot of error-catching code to things. And it seems to have improved stability, so I setup a fork for it: https://github.com/Nikorasu/phewer

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