[GH-ISSUE #72] Python3 export pve-cluster info 400 Bad Request #37

Closed
opened 2026-02-27 15:46:07 +03:00 by kerem · 3 comments
Owner

Originally created by @uranus829 on GitHub (Nov 4, 2021).
Original GitHub issue: https://github.com/proxmoxer/proxmoxer/issues/72

Originally assigned to: @jhollowe on GitHub.

I wrote a python script to export the pve cluster cluster information, but this script can be exported before, but now it can’t be executed, please help me take a look?I did not find any exceptions in this sentence, because this script is in another version with the same pve It can be executed under the cluster. Please help, thanks.

python3 list-pool.py


Traceback (most recent call last):
  File "list-pool-prd.py", line 58, in 
    conf = proxmox.nodes(node['node']).qemu(vm['vmid']).config.get()
  File "/usr/local/lib/python3.5/dist-packages/proxmoxer/core.py", line 123, in get
    return self(args)._request("GET", params=params)
  File "/usr/local/lib/python3.5/dist-packages/proxmoxer/core.py", line 110, in _request
    (self._store["serializer"].loads(resp) or {}).get('errors')
proxmoxer.core.ResourceException: 400 Bad Request: Result verification failed

image


#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from proxmoxer import ProxmoxAPI
import re
import xlsxwriter
import pandas as pd

workbook = xlsxwriter.Workbook('pve.xlsx')
worksheet = workbook.add_worksheet(u'pve')
head_format = workbook.add_format()
head_format.set_border(1)
head_format.set_bg_color('silver')
head_format.set_bold()
headings = ('NODE','VMID','VMNAME','POOL','STATUS','IP','DESCRIPTION')
worksheet.write_row(0, 0, headings, head_format)
row = 1
rowdata = []

proxmox = ProxmoxAPI('127.0.0.1', user='root@pam', password='XXX', verify_ssl=False)

pooldict = {}
for pool in proxmox.pools.get():
  p = proxmox.pools(pool['poolid']).get()
  memberlist = p.get("members")
  for item in memberlist:
    id = item.get("id")
    if id.startswith("lxc"):
      pooldict[id[4:]] = pool['poolid']
    if id.startswith("qemu"):
      pooldict[id[5:]] = pool['poolid']

patt = re.compile(r'ip=.*/\d+')
for node in proxmox.nodes.get():
  for vm in proxmox.nodes(node['node']).lxc.get():
    conf = proxmox.nodes(node['node']).lxc(vm['vmid']).config.get()
    des = conf.get("description")
    des = des.strip().replace('\n', ' ').replace('\r', ' ') if des is not None else "/"
    ip = "/"
    net = conf.get("net0")
    if net is not None:
      m = re.search(patt, net)
      ip = m.group(0)[3:] if m is not None else "/"
    rowdata.clear()
    rowdata.append(node['node'])
    rowdata.append(vm['vmid'])
    rowdata.append(vm['name'])
    if vm['vmid'] in pooldict.keys():
      rowdata.append(pooldict[vm['vmid']])
    else:
      rowdata.append("/")
    rowdata.append(vm['status'])
    rowdata.append(ip)
    rowdata.append(des)
    worksheet.write_row(row, 0, rowdata)
    row += 1
  for vm in proxmox.nodes(node['node']).qemu.get():
    conf = proxmox.nodes(node['node']).qemu(vm['vmid']).config.get()
    des = conf.get("description")
    des = des.strip().replace('\n', ' ').replace('\r', ' ') if des is not None else "/"
    ip = "/"
    net = conf.get("net0")
    if net is not None:
      m = re.search(patt, net)
      ip = m.group(0)[3:] if m is not None else "/"
    rowdata.clear()
    rowdata.append(node['node'])
    rowdata.append(vm['vmid'])
    rowdata.append(vm['name'])
    if vm['vmid'] in pooldict.keys():
      rowdata.append(pooldict[vm['vmid']])
    else:
      rowdata.append("/")
    rowdata.append(vm['status'])
    rowdata.append(ip)
    rowdata.append(des)
    worksheet.write_row(row, 0, rowdata)
    row += 1
workbook.close()
#
df = pd.DataFrame(pd.read_excel('./pve.xlsx'))
df = df.set_index(['NODE','VMID'])
df = df.sort_index()
df.to_excel(r'./pve.xlsx')
#df.to_excel('./pve_sorted.xlsx')
Originally created by @uranus829 on GitHub (Nov 4, 2021). Original GitHub issue: https://github.com/proxmoxer/proxmoxer/issues/72 Originally assigned to: @jhollowe on GitHub. I wrote a python script to export the pve cluster cluster information, but this script can be exported before, but now it can’t be executed, please help me take a look?I did not find any exceptions in this sentence, because this script is in another version with the same pve It can be executed under the cluster. Please help, thanks. python3 list-pool.py <pre><code> Traceback (most recent call last): File "list-pool-prd.py", line 58, in <module> conf = proxmox.nodes(node['node']).qemu(vm['vmid']).config.get() File "/usr/local/lib/python3.5/dist-packages/proxmoxer/core.py", line 123, in get return self(args)._request("GET", params=params) File "/usr/local/lib/python3.5/dist-packages/proxmoxer/core.py", line 110, in _request (self._store["serializer"].loads(resp) or {}).get('errors') proxmoxer.core.ResourceException: 400 Bad Request: Result verification failed </code></pre> ![image](https://user-images.githubusercontent.com/46716344/140244770-441febe5-7c4d-4d3e-8080-adf2933d999c.png) <pre><code> #!/usr/bin/env python3 # -*- coding: utf-8 -*- from proxmoxer import ProxmoxAPI import re import xlsxwriter import pandas as pd workbook = xlsxwriter.Workbook('pve.xlsx') worksheet = workbook.add_worksheet(u'pve') head_format = workbook.add_format() head_format.set_border(1) head_format.set_bg_color('silver') head_format.set_bold() headings = ('NODE','VMID','VMNAME','POOL','STATUS','IP','DESCRIPTION') worksheet.write_row(0, 0, headings, head_format) row = 1 rowdata = [] proxmox = ProxmoxAPI('127.0.0.1', user='root@pam', password='XXX', verify_ssl=False) pooldict = {} for pool in proxmox.pools.get(): p = proxmox.pools(pool['poolid']).get() memberlist = p.get("members") for item in memberlist: id = item.get("id") if id.startswith("lxc"): pooldict[id[4:]] = pool['poolid'] if id.startswith("qemu"): pooldict[id[5:]] = pool['poolid'] patt = re.compile(r'ip=.*/\d+') for node in proxmox.nodes.get(): for vm in proxmox.nodes(node['node']).lxc.get(): conf = proxmox.nodes(node['node']).lxc(vm['vmid']).config.get() des = conf.get("description") des = des.strip().replace('\n', ' ').replace('\r', ' ') if des is not None else "/" ip = "/" net = conf.get("net0") if net is not None: m = re.search(patt, net) ip = m.group(0)[3:] if m is not None else "/" rowdata.clear() rowdata.append(node['node']) rowdata.append(vm['vmid']) rowdata.append(vm['name']) if vm['vmid'] in pooldict.keys(): rowdata.append(pooldict[vm['vmid']]) else: rowdata.append("/") rowdata.append(vm['status']) rowdata.append(ip) rowdata.append(des) worksheet.write_row(row, 0, rowdata) row += 1 for vm in proxmox.nodes(node['node']).qemu.get(): conf = proxmox.nodes(node['node']).qemu(vm['vmid']).config.get() des = conf.get("description") des = des.strip().replace('\n', ' ').replace('\r', ' ') if des is not None else "/" ip = "/" net = conf.get("net0") if net is not None: m = re.search(patt, net) ip = m.group(0)[3:] if m is not None else "/" rowdata.clear() rowdata.append(node['node']) rowdata.append(vm['vmid']) rowdata.append(vm['name']) if vm['vmid'] in pooldict.keys(): rowdata.append(pooldict[vm['vmid']]) else: rowdata.append("/") rowdata.append(vm['status']) rowdata.append(ip) rowdata.append(des) worksheet.write_row(row, 0, rowdata) row += 1 workbook.close() # df = pd.DataFrame(pd.read_excel('./pve.xlsx')) df = df.set_index(['NODE','VMID']) df = df.sort_index() df.to_excel(r'./pve.xlsx') #df.to_excel('./pve_sorted.xlsx') </pre></code>
Author
Owner

@jhollowe commented on GitHub (Nov 5, 2021):

Just to confirm, you can run the script with proxmoxer<1.2.0 and it works but running proxmoxer==1.2.0 on the exact same PVE causes the above error?

<!-- gh-comment-id:961579446 --> @jhollowe commented on GitHub (Nov 5, 2021): Just to confirm, you can run the script with proxmoxer<1.2.0 and it works but running proxmoxer==1.2.0 on the exact same PVE causes the above error?
Author
Owner

@jhollowe commented on GitHub (Nov 5, 2021):

Are you able to determine what VMID the script is failing on? try adding a print(vm['vmid']) right before the failing call.

Once you have the ID that it crashes on, please run qm config <the_vm_id> on the node. From some Google-ing, it looks like this is not a problem with proxmoxer but is an error that PVE is throwing due to a problem with a VM config.

<!-- gh-comment-id:961581988 --> @jhollowe commented on GitHub (Nov 5, 2021): Are you able to determine what VMID the script is failing on? try adding a `print(vm['vmid'])` right before the failing call. Once you have the ID that it crashes on, please run `qm config <the_vm_id>` on the node. From some Google-ing, it looks like this is not a problem with proxmoxer but is an error that PVE is throwing due to a problem with a VM config.
Author
Owner

@uranus829 commented on GitHub (Nov 5, 2021):

@jhollowe Hi,This problem has been solved, the script can be executed by adding the print statement and deleting it. It is not a problem with proxmoxer, thanks!

<!-- gh-comment-id:961588148 --> @uranus829 commented on GitHub (Nov 5, 2021): @jhollowe Hi,This problem has been solved, the script can be executed by adding the print statement and deleting it. It is not a problem with proxmoxer, thanks!
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#37
No description provided.