Stuck Redis challenge Python

I’m stuck on Stage #rg2

I’ve no idea why this issue is happening

Here are my logs:

[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:

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

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

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

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?

2 Likes

yea that was the issue, thanks man!

1 Like

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