Help! Stuck on Stage #RG2

I used the following code as shown in the video for 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!")

    pong = "+PONG\r\n"

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

    with conn:
        conn.recv(1024)
        conn.send(pong.encode())


if __name__ == "__main__":
    main()

I get the following error:

remote: [stage-2] Running tests for Stage #2: Respond to PING
remote: [stage-2] $ ./spawn_redis_server.sh
remote: [your_program] Logs from your program will appear here!
remote: [stage-2] $ redis-cli ping
remote: [stage-2] Received: "" (no content received)
remote: [stage-2]            ^ error
remote: [stage-2] Error: Expected start of a new RESP value (either +, -, :, $ or *)
remote: [stage-2] Test failed (try setting 'debug: true' in your codecrafters.yml to see more details)
remote: 
remote: Try our CLI to run tests faster without Git: https://codecrafters.io/cli
remote: 
remote: View stage instructions: https://app.codecrafters.io/courses/redis.
remote: 
To https://git.codecrafters.io/2ca2199afd4af9cb
   e751b5e..f9e6861  master -> master

@shahfazz Is it possible that your changes aren’t committed before running git push? The code above looks fine to me :thinking:

Thanks for the response @rohitpaulk

I ran the instruction again

git add .
git commit --allow-empty -m “pass stage”
git push origin master

I get the following error-

@shahfazz ➜ /workspaces/desktop-tutorial (main) $ git add .

git push origin master@shahfazz ➜ /workspaces/desktop-tutorial (main) $ git commit --allow-empty -m “pass stage”
[main 8be6864] pass stage
@shahfazz ➜ /workspaces/desktop-tutorial (main) $ git push origin master
error: src refspec master does not match any
error: failed to push some refs to ‘https://github.com/shahfazz/desktop-tutorial

@shahfazz when you did the initial clone, you should’ve gotten master as the branch. Looks like you’ve got main instead, based on your logs. Can you try switching to master?

Also, if you’re able to share how you ended up with main that’d be useful, maybe there’s a case we aren’t handling correctly.

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

Note: I’ve updated the title of this post to include the stage ID (#RG2). You can learn about the stages rename here: Upcoming change: Stages overhaul.