Python3 export cluster info 400 Bad Request

uranus12

New Member
Jun 22, 2021
20
0
1
40
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?

python3 list-pool.py
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 105, in get
    return self(args)._request("GET", params=params)
  File "/usr/local/lib/python3.5/dist-packages/proxmoxer/core.py", line 94, in _request
    resp.reason, resp.content))
proxmoxer.core.ResourceException: 400 Bad Request: Result verification failed - b'{"data":null,"errors":{"boot":"value does not match the regex pattern"}}'


Python:
#!/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')
 
hi,

the error is: 400 Bad Request: Result verification failed - b'{"data":null,"errors":{"boot":"value does not match the regex pattern"}}'

seems to happen on line 58 when fetching the config of a specific guest i suppose. i would put a print before that to show the ID of the VM, then look at the configuration file for that specific VM on your machine. it might have some wrong values (you can post it here if you can't find the error)
 
hi,

the error is: 400 Bad Request: Result verification failed - b'{"data":null,"errors":{"boot":"value does not match the regex pattern"}}'

seems to happen on line 58 when fetching the config of a specific guest i suppose. i would put a print before that to show the ID of the VM, then look at the configuration file for that specific VM on your machine. it might have some wrong values (you can post it here if you can't find the error)
Hi,@oguz
Line 58 is
Code:
conf = proxmox.nodes(node['node']).qemu(vm['vmid']).config.get()
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
 
Last edited:
I did not find any exceptions in this sentence,
yes the problem is not with that specific line per say, it's what happens when some config is pulled:
Code:
{"data":null,"errors":{"boot":"value does not match the regex pattern"}}
that error is from our API, it means one of your guests has a boot parameter which doesn't match the allowed regex pattern (in the configuration file).
because this script is in another version with the same pve It can be executed under the cluster
that's probably because that node doesn't have a VM with faulty configuration.
just add a print(vm['vmid']) and you'll know which VM is causing trouble. then you can check the configuration file in /etc/pve/qemu-server/VMID.conf
 
yes the problem is not with that specific line per say, it's what happens when some config is pulled:
Code:
{"data":null,"errors":{"boot":"value does not match the regex pattern"}}
that error is from our API, it means one of your guests has a boot parameter which doesn't match the allowed regex pattern (in the configuration file).

that's probably because that node doesn't have a VM with faulty configuration.
just add a print(vm['vmid']) and you'll know which VM is causing trouble. then you can check the configuration file in /etc/pve/qemu-server/VMID.conf
Is there any problem with the output vmid? There are multiple vmid values after execution.
Code:
150
208
176
130
138
142
151
124
271
117
182
270
131
114
291
339
165
301
167
306
186
346
345
120
228
347
325
342
323
109
322
320
199
324
251
231
144
321
328
162
326
309
116
204
166
159
246
122
234
164
189
350
135
193
230
195
168
137
171
106
118
113
158
250
210
173
282
121
209
211
240
286
242
249
198
327
260
254
241
253
136
236
226
197
140
232
139
115
229
153
191
205
248
259
172
147
123
143
146
233
141
149
155
170
161
156
175
174
160
169
148
133
194
221
360
188
289
247
311
134
145
307
132
157
302
203
225
119
310
305
239
3008
304
303
202
337
335
318
252
154
336
330
332
319
334
179
180
220
177
348
400
333
 
well do you get the error again?...

if you put the print in the right place it should just error out right after the faulty VMID is printed, then you'll know.
 
well do you get the error again?...

if you put the print in the right place it should just error out right after the faulty VMID is printed, then you'll know.
A very strange thing, I added the print to the last position, and then executed the script only output a vmid, no error was reported, and then delete the print, the script can be executed. grateful!
1636019444182.png
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!