# HTTP Server challenge - python

**URL:** https://forum.codecrafters.io/t/http-server-challenge-python/856
**Category:** Challenges
**Tags:** challenge:http-server
**Created:** [June 25, 2024, 6:43pm UTC](https://forum.codecrafters.io/t/http-server-challenge-python/856 "2024-06-25T18:43:59Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![muratcanozdemir](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/muratcanozdemir/32/781_2.png) [@muratcanozdemir](https://forum.codecrafters.io/u/muratcanozdemir)
#### Post date: [June 25, 2024, 6:43pm UTC](https://forum.codecrafters.io/t/http-server-challenge-python/856/1 "2024-06-25T18:43:59Z")

</div>

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

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

```

---

<div class="post-metadata">

### Author: ![RickHPotter](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/rickhpotter/32/788_2.png) [@RickHPotter](https://forum.codecrafters.io/u/RickHPotter)
#### Post date: [June 26, 2024, 11:44pm UTC](https://forum.codecrafters.io/t/http-server-challenge-python/856/2 "2024-06-26T23:44:10Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)
#### Post date: [October 4, 2024, 3:30am UTC](https://forum.codecrafters.io/t/http-server-challenge-python/856/3 "2024-10-04T03:30:22Z")

</div>

@muratcanozdemir Just checking, do you still need any assistance with this?

---

<div class="post-metadata">

### Author: ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)
#### Post date: [October 11, 2024, 7:09am UTC](https://forum.codecrafters.io/t/http-server-challenge-python/856/4 "2024-10-11T07:09:43Z")

</div>

Closing this thread due to inactivity. If you still need assistance, feel free to reopen or start a new discussion!

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/3X/7/0/700657133935c15703e22c7c8870394f6e6dc27d.svg) [@system](https://forum.codecrafters.io/u/system)
#### Post date: [October 16, 2024, 7:10am UTC](https://forum.codecrafters.io/t/http-server-challenge-python/856/5 "2024-10-16T07:10:20Z")

</div>

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.
