10000 Add workaround for broken `pvesh` output. by reitermarkus · Pull Request #205 · proxmoxer/proxmoxer · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add workaround for broken pvesh output. #205

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

Merged
merged 2 commits into from
Apr 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file 10000
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions proxmoxer/backends/command_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,24 @@ def upload_file_obj(self, file_obj, remote_path):

class JsonSimpleSerializer:
def loads(self, response):
# FIXME: Workaround for https://bugzilla.proxmox.com/show_bug.cgi?id=4333.
#
# With each iteration, try parsing one fewer line, until
# we reach the beginning of the actual JSON message.
try:
return json.loads(response.content)
except (UnicodeDecodeError, ValueError):
return {"errors": response.content}
content = response.content
if isinstance(content, bytes):
content = content.decode("utf-8")
content_lines = content.splitlines()
while content_lines:
try:
return json.loads("\n".join(content_lines))
except ValueError:
content_lines = content_lines[1:]
except UnicodeDecodeError:
pass

return {"errors": response.content}

def loads_errors(self, response):
try:
Expand Down
13 changes: 13 additions & 0 deletions tests/test_command_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,19 @@ def test_loads_not_unicode(self):

assert act_output == exp_output

def test_loads_json_preceded_by_non_json(self):
input_str = """
virtio0: successfully created disk 'local-zfs:vm-7777-disk-0,discard=on,iothread=1,size=4G'
"UPID:net2-pve:002605B4:00FB48C2:62B9E7EB:qmcreate:7777:root@pam:"
"""
exp_output = "UPID:net2-pve:002605B4:00FB48C2:62B9E7EB:qmcreate:7777:root@pam:"

response = command_base.Response(input_str.encode("utf-8"), 200, 201)

act_output = self._serializer.loads(response)

assert act_output == exp_output


class TestCommandBaseBackend:
backend = command_base.CommandBaseBackend()
Expand Down
Loading
0