Python unix sockets doesn't work ? Can't find any explanation here

Viewed 60

I have running mpv player which supports IPC control throught unix sockets, and it works shiny well:

$ echo '{ "command": ["set_property", "pause", true ] }' | socat - /tmp/mpvsocket

{"request_id":0,"error":"success"}

Now I want the same from python script (Python 3.9):

import os, sys
import socket
import errno

resp = ""
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
s.connect('/tmp/mpvsocket')
s.settimeout(2)

message = '{ "command": ["set_property", "pause", true] }'

s.send(message.encode())

try:
    msg = s.recv(4096)
    resp = msg.decode()
except OSError as e:
    # Something else happened, handle error, exit, etc.
    print("Error reciving reply from ipc sock:" + str(e.args[0]))
print(resp)

And now I gett this gloomy thing:

Error reciving reply from ipc sock:timed out

Of course playback didn't pause either.

Any idea what is wrong here ?

1 Answers

Comment from @Selcuk is correct. Just needed to add "\n".

Related