canonical / pylxd

Python module for LXD
https://pylxd.readthedocs.io/en/latest/
Apache License 2.0
251 stars 133 forks source link

container.execute Failed to receive data ConnectionResetError: [Errno 104] Connection reset by peer ws4py/websocket.py #523

Closed kimfaint closed 1 year ago

kimfaint commented 1 year ago

I am consistently getting an error with the container.execute method.

For example:

import subprocess
from pylxd import Client, __version__ as pylxd_version

ret = subprocess.run(['lxd', '--version'], stdout=subprocess.PIPE)
lxd_version = ret.stdout.decode().strip()
print(f'LXD version {lxd_version}')
print(f'pylxd version {pylxd_version}')

name = 'o8a221'
client = Client()
print('containers.get')
container = client.containers.get(name)
print('container.execute')
(exit_code, output, error) = container.execute(['uname', '-a'])
print(f'exit_code: {exit_code}')
print(f'output: {output}')
print(f'error: {error}')

When run:

LXD version 5.7
pylxd version 2.3.1
containers.get
/mnt/data/rc/psp/test.1/venv/lib/python3.10/site-packages/pylxd/models/_model.py:146: UserWarning: Attempted to set unknown attribute "project" on instance of "Container"
  warnings.warn(
container.execute
Failed to receive data
Traceback (most recent call last):
  File "/mnt/data/rc/psp/test.1/venv/lib/python3.10/site-packages/ws4py/websocket.py", line 394, in once
    b = self.sock.recv(self.reading_buffer_size)
ConnectionResetError: [Errno 104] Connection reset by peer
exit_code: 0
output: Linux o8a221 5.15.0-50-generic #56-Ubuntu SMP Tue Sep 20 13:23:26 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

error: 

So the execute is successful, the correct data seems to be returned in the exit_code and output. Yet is is printing a Failed to receive data error. I think this started sometime within the last month.

Also this is using ws4py==0.5.1.

qupfer commented 1 year ago

have the same issue:

import pylxd
lxd = pylxd.Client()
first= lxd.containers.all()[0]
a,b,c=first.execute(["ls","-lah"])
print(a)
print(b)
print(c)
/usr/lib/python3/dist-packages/pylxd/models/operation.py:76: UserWarning: Attempted to set unknown attribute "location" on instance of "Operation"
  warnings.warn(
Failed to receive data
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/ws4py/websocket.py", line 390, in once
    b = self.sock.recv(self.reading_buffer_size)
ConnectionResetError: [Errno 104] Connection reset by peer
0
total 756K
drwx------ 1 root    root     152 Oct 27 09:05 .
drwxr-xr-x 1 root    root     160 Oct 25 12:58 ..
-rw------- 1 root    root    4.0K Oct 31 20:39 .bash_history
-rw-r--r-- 1 root    root    3.1K Oct 15  2021 .bashrc
drwx------ 1 root    root      58 Oct 27 08:54 .cache
drwx------ 1 root    root      30 Oct 27 08:54 .config
-rw------- 1 root    root      20 Oct 26 12:54 .lesshst
drwxr-xr-x 1 root    root      10 Oct 26 12:25 .local
-rw-r--r-- 1 root    root     161 Jul  9  2019 .profile
drwx------ 1 root    root      82 Oct 27 08:57 .ssh