I am trying to request the usage metrics from a virtual machine I have running on Azure Devops. I know it's online because i've sent a ping. However, every time I try to run the program with the correct Get information filled in it gives me an error:
{"error":{"code":"AuthenticationFailed","message":"Authentication failed. The 'Authorization' header is missing."}}
I am following the instructions here: https://learn.microsoft.com/en-us/azure/virtual-machines/linux/metrics-vm-usage-rest
import requests
BASE_URL = "GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmname}/providers/microsoft.insights/metrics?api-version=2018-01-01&metricnames=Percentage%20CPU×pan=2018-06-05T03:00:00Z/2018-06-07T03:00:00Z"
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer {myPAT}"
}
response = requests.get(BASE_URL,headers)
print(response.text)
The bug lies in my Authorization header, what am I missing?
Edit: Actually this question Is there a way to call Azure Devops via python using 'requests'? solved my issue but now I have another error "{"error":{"code":"InvalidAuthenticationToken","message":"The access token is invalid."}}". I am reading the docs. https://learn.microsoft.com/en-us/azure/active-directory-b2c/access-tokens Thank you.
