Python sockets definitely have their quirks, although they seem to be better than they were. Many components of the Python socket library call out to the OS to use their components. Back in 2.7 I had some weird issues with timeouts on a Windows machine. I can’t remember the fix, but I think I just brute forced a correct timeout with a retry functionality.
One thing I just noticed is that your .recv is set to 5 while that command should only return 4. This doesn’t explain the timeout, but its a small thing.
Is it a blocking socket or non-blocking?
Are you opening and closing the socket for every send/recv?
I did notice that if I don’t wait a fraction of a second before re-opening a socket i’ll get an error so it may be a situation where the socket is initialized, but its not quite ready for data.