[GH-ISSUE #49] proxmox.get(item) not working? #24

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

Originally created by @edofullin on GitHub (Apr 15, 2021).
Original GitHub issue: https://github.com/proxmoxer/proxmoxer/issues/49

Originally assigned to: @jhollowe on GitHub.

I get errors with this code:

from proxmoxer import ProxmoxAPI

proxmox=ProxmoxAPI('proxmox.myhost.net', user='user@pve', password='secret', verify_ssl=False)

vms = []
containers = []

for node in proxmox.get("nodes"):

            for virtman in proxmox.get(f"nodes/{node}/qemu"):
                vms.append(virtman["vmid"])

            for cont in proxmox.get(f"nodes/{node}/lxc"):
                containers.append(cont["vmid"])

The error in question is on the outermost for loop and is

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'ProxmoxResource' object is not iterable

I'm using Proxmox 6.3-6 and Python 3.9

Using proxmox.nodes.get() insted works correctly, but I would like to use proxmox.get("nodes")

Am I doing something wrong?

Originally created by @edofullin on GitHub (Apr 15, 2021). Original GitHub issue: https://github.com/proxmoxer/proxmoxer/issues/49 Originally assigned to: @jhollowe on GitHub. I get errors with this code: ``` from proxmoxer import ProxmoxAPI proxmox=ProxmoxAPI('proxmox.myhost.net', user='user@pve', password='secret', verify_ssl=False) vms = [] containers = [] for node in proxmox.get("nodes"): for virtman in proxmox.get(f"nodes/{node}/qemu"): vms.append(virtman["vmid"]) for cont in proxmox.get(f"nodes/{node}/lxc"): containers.append(cont["vmid"]) ``` The error in question is on the outermost for loop and is ``` Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'ProxmoxResource' object is not iterable ``` I'm using Proxmox 6.3-6 and Python 3.9 Using proxmox.nodes.get() insted works correctly, but I would like to use proxmox.get("nodes") Am I doing something wrong?
Author
Owner

@jhollowe commented on GitHub (Apr 16, 2021):

Using proxmox.nodes.get() insted works correctly, but I would like to use proxmox.get("nodes")

Is there a specific reason you can't use the proxmox.nodes.get() format?

What version of proxmoxer are you using?

<!-- gh-comment-id:820843779 --> @jhollowe commented on GitHub (Apr 16, 2021): > Using proxmox.nodes.get() insted works correctly, but I would like to use proxmox.get("nodes") Is there a specific reason you can't use the `proxmox.nodes.get()` format? What version of proxmoxer are you using?
Author
Owner

@edofullin commented on GitHub (Apr 16, 2021):

The reason was that unit testing was going to be easier, but eventually I managed to use the proxmox.nodes.get() notation anyway.

The README should be updated if the proxmox.get(string) format is no longer supported.

Using latest version, 1.1.1

<!-- gh-comment-id:820998108 --> @edofullin commented on GitHub (Apr 16, 2021): The reason was that unit testing was going to be easier, but eventually I managed to use the `proxmox.nodes.get()` notation anyway. The README should be updated if the `proxmox.get(string)` format is no longer supported. Using latest version, 1.1.1
Author
Owner

@jhollowe commented on GitHub (Apr 19, 2021):

Yeah, it looks like proxmox.something.get() and proxmox.get("something") return different things due to one being a ProxmoxResource object and one being a ProxmoxAPI object.

I think making ProxmoxAPI inherit from ProxmoxResource rather than ProxmoxResourceBase might fix this issue, but I'll need to test that theory and see if that actually works.

<!-- gh-comment-id:822806653 --> @jhollowe commented on GitHub (Apr 19, 2021): Yeah, it looks like `proxmox.something.get()` and `proxmox.get("something")` return different things due to one being a `ProxmoxResource` object and one being a `ProxmoxAPI` object. I think making `ProxmoxAPI` inherit from `ProxmoxResource` rather than `ProxmoxResourceBase` might fix this issue, but I'll need to test that theory and see if that actually works.
Author
Owner

@jhollowe commented on GitHub (May 13, 2021):

If you don't need the entire path to be on the string, you can use the following:

for node in proxmox.nodes.get():
  for virtman in proxmox.nodes.get(f"{node['node']}/qemu"):
    vms.append(virtman["vmid"])
  for cont in proxmox.nodes.get(f"{node['node']}/lxc"):
    containers.append(cont["vmid"])
<!-- gh-comment-id:840275500 --> @jhollowe commented on GitHub (May 13, 2021): If you don't need the entire path to be on the string, you can use the following: ```python for node in proxmox.nodes.get(): for virtman in proxmox.nodes.get(f"{node['node']}/qemu"): vms.append(virtman["vmid"]) for cont in proxmox.nodes.get(f"{node['node']}/lxc"): containers.append(cont["vmid"]) ```
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#24
No description provided.