Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
vilhelmprytz opened this issue Mar 10, 2020 · 4 comments
Open

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

vilhelmprytz opened this issue Mar 10, 2020 · 4 comments

Comments

@vilhelmprytz
Copy link
Contributor

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

@vilhelmprytz vilhelmprytz changed the title "NpipeSocket object has no attribute '_sock' 'NpipeSocket' object has no attribute '_sock' Mar 10, 2020
@nitko12
Copy link

nitko12 commented Dec 23, 2020

Hi,

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

@GerasimovRM
Copy link

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
Copy link

Any solution? I've just hit this problem

@vodibe
Copy link

vodibe commented Feb 25, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants