docker-py
docker-py copied to clipboard
'NpipeSocket' object has no attribute '_sock'
Hi!
I'm trying to send commands to the stdin of a container. On Linux, I can do this sending to the _sock like this.
container = self._docker_client.containers.get(test)
s = container.attach_socket(params={"stdin": 1, "stream": 1})
s._sock.send(f"{command}\n".encode("utf-8"))
s.close()
But, when I try to do this on Windows I get the following exception.
AttributeError: 'NpipeSocket' object has no attribute '_sock'
Is there any equivalent way of getting _sock on the Windows socket?
If you want some context, this is where I'd like to use it: https://github.com/wilfred-dev/wilfred/blob/22c38862f162cb5c586df4f3de8d447cdddcf24a/wilfred/servers.py#L286
Hi,
did you somehow solve this issue, I've ran into it while running python module epicbox.
My problem is the same. When I start to research it, I saw that sock have type of NpipeSocket and dont have _sock field, but have setblocking method: call dir(sock):
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_address', '_closed', '_handle', '_recv_into_py2', '_response', '_timeout', 'accept', 'bind', 'close', 'connect', 'connect_ex', 'detach', 'dup', 'flags', 'getpeername', 'getsockname', 'getsockopt', 'gettimeout', 'ioctl', 'listen', 'makefile', 'recv', 'recv_into', 'recvfrom', 'recvfrom_into', 'send', 'sendall', 'sendto', 'setblocking', 'setsockopt', 'settimeout', 'shutdown']
Next I saw that:
File "<path>\venv\lib\site-packages\docker\transport\npipesocket.py", line 173, in settimeout self._timeout = win32pipe.NMPWAIT_NO_WAIT AttributeError: module 'win32pipe' has no attribute 'NMPWAIT_NO_WAIT'.
dir(win32pipe):
['CallNamedPipe', 'ConnectNamedPipe', 'CreateNamedPipe', 'CreatePipe', 'DisconnectNamedPipe', 'FdCreatePipe', 'GetNamedPipeClientProcessId', 'GetNamedPipeClientSessionId', 'GetNamedPipeHandleState', 'GetNamedPipeInfo', 'GetNamedPipeServerProcessId', 'GetNamedPipeServerSessionId', 'GetOverlappedResult', 'NMPWAIT_NOWAIT', 'NMPWAIT_USE_DEFAULT_WAIT', 'NMPWAIT_WAIT_FOREVER', 'PIPE_ACCESS_DUPLEX', 'PIPE_ACCESS_INBOUND', 'PIPE_ACCESS_OUTBOUND', 'PIPE_NOWAIT', 'PIPE_READMODE_BYTE', 'PIPE_READMODE_MESSAGE', 'PIPE_TYPE_BYTE', 'PIPE_TYPE_MESSAGE', 'PIPE_UNLIMITED_INSTANCES', 'PIPE_WAIT', 'PeekNamedPipe', 'SetNamedPipeHandleState', 'TransactNamedPipe', 'UNICODE', 'WaitNamedPipe', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'error', 'popen', 'popen2', 'popen3', 'popen4']
I changed from NMPWAIT_NO_WAIT to NMPWAIT_NOWAIT etc
I see many errors step by step and can not solve all problems. It is more likely that the problem occurs on both the windows system and the docker API client. P.S. if you run this code in docker container, everything will work great.
Let me know if you have news on this issue.
Any solution? I've just hit this problem