HTTP Server challenge - python

I’m stuck on Stage #8

I’ve tried to account for missing headers, read the body fully and create the directory if not exists gracefully, yet my test logs are still:

Failed to read response:
[tester::#QV8] Received: “” (no content received)
[tester::#QV8] ^ error
[tester::#QV8] Error: Expected: HTTP-version, Received: “”
[tester::#QV8] Test failed

               elif method == "POST":
                    if url_path.startswith("/files/"):
                        filename = url_path[len("/files/"):]
                        file_path = os.path.join(directory_path, filename)

                        os.makedirs(os.path.dirname(file_path), exist_ok=True)
                        print(f"Creating file: {file_path}")

                        try:
                            with open(file_path, "wb") as f:
                                f.write(body)
                                response = "HTTP/1.1 201 Created\r\n\r\n".encode()
                        except Exception as e:
                            print(f"Error writing file: {e}")
                            response = "HTTP/1.1 500 Internal Server Error\r\n\r\n".encode()
                    else:
                        response = "HTTP/1.1 404 Not Found\r\n\r\n".encode()

I dont think you are supposed to create the folder. Maybe you’re getting permission denied because and your code is just crashing and ends up sending nothing back as response.