KeyVault API call error
Hey, I was trying to make an api call using the endpoint of key vaults.
Here's my code:
def get_token():
r = requests.post("https://login.microsoftonline.com/TenantID/oauth2/token",data={"grant_type": "client_credentials","client_secret": "xxxxx","client_id": "xxxxxxx","resource": "https://management.azure.com"})
ret_body = r.json()
return ret_body['access_token']
token = get_token()
headers = {'Authorization': 'Bearer ' + token}
#print(headers)
conn = http.client.HTTPSConnection('management.azure.com')
conn.request("GET", '/subscriptions/xxxxxx/providers/Microsoft.KeyVault/vaults?api-version=2021-11-01-preview', "", headers)
response = conn.getresponse()
key_data = response.read()
key_data = key_data.decode('utf-8')
key_data = json.loads(key_data)
print(key_data)
I haven't written the IDs here, but I have written it on my local code.
This call used to work always until I tried it out again today. This is the output I am getting
{'value': [], 'nextLink': 'https://management.azure.com/subscriptions/xxxxx/providers/Microsoft.KeyVault/vaults?api-version=2021-11-01-preview&$skiptoken=ServiceBased,dGVzdHN0b3x0ZXN0dmF1bHQ2OTA='}
Again, I have removed the subscription while pasting it here. But I've mentioned what happens when I click the link below.
I tried changing the api versions too. Didn't work, I printed the header as well. Nothing was wrong. When I clicked on the "nextLink", this was the error I got.
{"error":{"code":"AuthenticationFailed","message":"Authentication failed. The 'Authorization' header is missing."}}
Is there something wrong with the code? Or has the endpoint somehow changed (highly unlikely)?