[GH-ISSUE #89] When using backend openssh agent.exec.post(command="ls") works, "ls -l" says TypeError: cannot use a string pattern on a bytes-like object #49

Closed
opened 2026-02-27 15:46:10 +03:00 by kerem · 1 comment
Owner

Originally created by @guerby on GitHub (Feb 25, 2022).
Original GitHub issue: https://github.com/proxmoxer/proxmoxer/issues/89

Originally assigned to: @jhollowe on GitHub.

Hi,

When connecting to a server with openssh backend I can exec a command "ls" via the agent successfully:

proxmox.nodes("r640c").qemu("149").agent.exec.post(command="ls")
{'pid': 28016}
proxmox.nodes("r640c").qemu("149").agent("exec-status").get(pid=28016)
{'exitcode': 0, 'exited': 1, 'out-data': '...n'}

But when I try "ls -l" I get TypeError: cannot use a string pattern on a bytes-like object :

proxmox.nodes("r640c").qemu("149").agent.exec.post(command="ls -l")
Traceback (most recent call last):
File "", line 1, in
File "/home/lguerby/.local/lib/python3.7/site-packages/proxmoxer/core.py", line 126, in post
return self(args)._request("POST", data=data)
File "/home/lguerby/.local/lib/python3.7/site-packages/proxmoxer/core.py", line 100, in _request
resp = self._store["session"].request(method, url, data=data or None, params=params)
File "/home/lguerby/.local/lib/python3.7/site-packages/proxmoxer/backends/base_ssh.py", line 60, in request
500)
File "/home/lguerby/.local/lib/python3.7/site-packages/proxmoxer/backends/base_ssh.py", line 59, in
(int(s.split()[0]) for s in stderr.splitlines() if match(s)),
File "/home/lguerby/.local/lib/python3.7/site-packages/proxmoxer/backends/base_ssh.py", line 55, in match
def match(s): return re.match(r'\d\d\d [a-zA-Z]', s)
File "/usr/lib/python3.7/re.py", line 173, in match
return _compile(pattern, flags).match(string)
TypeError: cannot use a string pattern on a bytes-like object

When I use the https backend both "ls" and "ls -l" work. I suspect an issue with space handling/quoting or may be I missed something for post command=.

Thanks for proxmoxer!

Originally created by @guerby on GitHub (Feb 25, 2022). Original GitHub issue: https://github.com/proxmoxer/proxmoxer/issues/89 Originally assigned to: @jhollowe on GitHub. Hi, When connecting to a server with openssh backend I can exec a command "ls" via the agent successfully: >>> proxmox.nodes("r640c").qemu("149").agent.exec.post(command="ls") {'pid': 28016} >>> proxmox.nodes("r640c").qemu("149").agent("exec-status").get(pid=28016) {'exitcode': 0, 'exited': 1, 'out-data': '...n'} But when I try "ls -l" I get TypeError: cannot use a string pattern on a bytes-like object : >>> proxmox.nodes("r640c").qemu("149").agent.exec.post(command="ls -l") Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/lguerby/.local/lib/python3.7/site-packages/proxmoxer/core.py", line 126, in post return self(args)._request("POST", data=data) File "/home/lguerby/.local/lib/python3.7/site-packages/proxmoxer/core.py", line 100, in _request resp = self._store["session"].request(method, url, data=data or None, params=params) File "/home/lguerby/.local/lib/python3.7/site-packages/proxmoxer/backends/base_ssh.py", line 60, in request 500) File "/home/lguerby/.local/lib/python3.7/site-packages/proxmoxer/backends/base_ssh.py", line 59, in <genexpr> (int(s.split()[0]) for s in stderr.splitlines() if match(s)), File "/home/lguerby/.local/lib/python3.7/site-packages/proxmoxer/backends/base_ssh.py", line 55, in match def match(s): return re.match(r'\d\d\d [a-zA-Z]', s) File "/usr/lib/python3.7/re.py", line 173, in match return _compile(pattern, flags).match(string) TypeError: cannot use a string pattern on a bytes-like object When I use the https backend both "ls" and "ls -l" work. I suspect an issue with space handling/quoting or may be I missed something for post command=. Thanks for proxmoxer!
Author
Owner

@jhollowe commented on GitHub (Mar 10, 2022):

There were two issues: the error got returned as a byte string and so the code (seen in the stack trace above) died when trying to parse it for the error. Second, the command was not handled any different from all the other parameters and the SSH/CLI based backends need special handling for it (https needs special work too, it just wasn't as obvious it was broken).

I have initial fixes that I still need to add tests for and finalize if how I'm currently doing it is the best way. I also need to make sure this fix will not break any other API endpoints in PVE, PMS, or PBS.

<!-- gh-comment-id:1063659957 --> @jhollowe commented on GitHub (Mar 10, 2022): There were two issues: the error got returned as a byte string and so the code (seen in the stack trace above) died when trying to parse it for the error. Second, the command was not handled any different from all the other parameters and the SSH/CLI based backends need special handling for it (https needs special work too, it just wasn't as obvious it was broken). I have initial fixes that I still need to add tests for and finalize if how I'm currently doing it is the best way. I also need to make sure this fix will not break any other API endpoints in PVE, PMS, or PBS.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/proxmoxer#49
No description provided.