docker / docker-py

A Python library for the Docker Engine API
https://docker-py.readthedocs.io/
Apache License 2.0
6.83k stars 1.67k forks source link

'NpipeSocket' object has no attribute '_sock' #2524

Open vilhelmprytz opened 4 years ago

vilhelmprytz commented 4 years ago

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

nitko12 commented 3 years ago

Hi,

did you somehow solve this issue, I've ran into it while running python module epicbox.

GerasimovRM commented 1 year ago

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.

thenewguy commented 11 months ago

Any solution? I've just hit this problem

vodibe commented 8 months ago

Any updates so far? As stated here it seems an issue with python version, since 3.7 does the job. Also related: this. Official docs should propose a full working example.