401 Unauthorized when trying to use Proxmox API in Python to clone VM

rareness

New Member
Oct 18, 2023
3
0
1
Hey,

I'm trying to clone VM from one node to the other node, using the following code in Python:
Code:
data = {"name": "censored",  # Name for the new cloned virtual machine
"target": "censored2",  # The target node where the clone will be created (target_node)
}

headers = {
"Content-Type": "application/json"
}

password = "censored"
user = "censored4"
# Make the HTTP POST request to clone the VM
url = f"https://censored5:8006/api2/json/nodes/censored6/qemu/194/clone"
proxmox_response = requests.post(url, data=data, auth=(user, password), headers=headers)

if proxmox_response.status_code == 200:
print("VM cloning request successful.")
else:
print(f"VM cloning request failed with status code: {proxmox_response.status_code}")
print(proxmox_response.text)

However, I only get 401 unathorized error when trying to execute the code, can someone please help with it

For my user I have created an API token with privilege seperation, and it has all the required permissions for that operation: 'VM.Clone'and 'VM.Allocate' 'Datastore.AllocateSpace' 'SDN.Use'
 
Hi,
you are getting a 401 because proxmox doesn't support basic auth for the api.
There are two ways to get this working, you can either request a ticket cookie with your credentials and use that for
authentication, which would add an extra step to your request, or you create an API token and use that.

An explanation of both methods can be found in the documentation.

Hope this helps!
 

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!