# Stuck Redis challenge Python

**URL:** <https://forum.codecrafters.io/t/stuck-redis-challenge-python/6100>\
**Category:** Challenges\
**Tags:** challenge:redis\
**Created:** [March 5, 2025, 4:49pm UTC](https://forum.codecrafters.io/t/stuck-redis-challenge-python/6100 "2025-03-05T16:49:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Philip-peter](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/philip-peter/32/6303_2.png) [@Philip-peter](https://forum.codecrafters.io/u/Philip-peter)\
**Post date:** [March 5, 2025, 4:49pm UTC](https://forum.codecrafters.io/t/stuck-redis-challenge-python/6100/1 "2025-03-05T16:49:14Z")

</div>

I’m stuck on Stage #rg2

I’ve no idea why this issue is happening

Here are my logs:

```auto
[compile] Compilation successful.
Debug = true
[tester::#RG2] Running tests for Stage #RG2 (Respond to PING)
[tester::#RG2] $ ./spawn_redis_server.sh
[your_program] Logs from your program will appear here!
[tester::#RG2] Connection established, sending ping command...
[tester::#RG2] $ redis-cli PING
[tester::#RG2] Sent bytes: "*1\r\n$4\r\nPING\r\n"
[tester::#RG2] Received: "" (no content received)
[tester::#RG2] ^ error
[tester::#RG2] Error: Expected start of a new RESP2 value (either +, -, :, $ or *)
[tester::#RG2] Test failed
[tester::#RG2] Terminating program
[tester::#RG2] Program terminated successfully

```

And here’s a snippet of my code:

```python
#Uncomment this to pass the first stage
import socket

def main():
    # You can use print statements as follows for debugging, they'll be visible when running tests.
    print("Logs from your program will appear here!")

    #Uncomment this to pass the first stage
    
    server_socket = socket.create_server(("localhost", 6379), reuse_port=True)
    server_socket.accept() # wait for client
    connection, client_addr = server_socket.accept()

    pong = b"+PONG\r\n"

    with connection as c:
        data_recv = c.recv(1024)
        print(data_recv)
        c.send(pong)

if __name__ == " __main__":
    main()

```

---

<div class="post-metadata">

**Author:** ![eaverdeja](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/eaverdeja/32/4167_2.png) [@eaverdeja](https://forum.codecrafters.io/u/eaverdeja)\
**Post date:** [March 5, 2025, 5:50pm UTC](https://forum.codecrafters.io/t/stuck-redis-challenge-python/6100/2 "2025-03-05T17:50:46Z")

</div>

You probably need to encode your response before sending it off. Can you try that?

---

<div class="post-metadata">

**Author:** ![Philip-peter](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/philip-peter/32/6303_2.png) [@Philip-peter](https://forum.codecrafters.io/u/Philip-peter)\
**Post date:** [March 5, 2025, 6:25pm UTC](https://forum.codecrafters.io/t/stuck-redis-challenge-python/6100/3 "2025-03-05T18:25:00Z")

</div>

I have tried using the b literal and encode(), still same error

---

<div class="post-metadata">

**Author:** ![eaverdeja](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/eaverdeja/32/4167_2.png) [@eaverdeja](https://forum.codecrafters.io/u/eaverdeja)\
**Post date:** [March 5, 2025, 8:58pm UTC](https://forum.codecrafters.io/t/stuck-redis-challenge-python/6100/4 "2025-03-05T20:58:10Z")

</div>

Sorry, I hadn’t seen the `b` for the literal.

I see you have two calls to `server_socket.accept`. That might be messing things up - can you try removing the first one?

---

<div class="post-metadata">

**Author:** ![Philip-peter](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/philip-peter/32/6303_2.png) [@Philip-peter](https://forum.codecrafters.io/u/Philip-peter)\
**Post date:** [March 5, 2025, 9:48pm UTC](https://forum.codecrafters.io/t/stuck-redis-challenge-python/6100/5 "2025-03-05T21:48:46Z")

</div>

yea that was the issue, thanks man!

---

<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:** [March 10, 2025, 9:49pm UTC](https://forum.codecrafters.io/t/stuck-redis-challenge-python/6100/6 "2025-03-10T21:49:22Z")

</div>

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