'Updating repositories in Azure Devops with PAT token through Python
I am trying to disable a repo in Azure Devops through the API and I am having trouble authenticating to my Azure devops organization. I have the request correct but I keep getting a
401 client error Unauthorized for URL
I have a PAT token to authenticate, I am just not sure how to add that into the request body to be able to authenticate to Azure Devops. Below is the code that I am using to complete this. I have looked through all the documentation and I cannot find the syntax to complete this but I know a PAT token can be used to authenticate.
print("Would you like to Disable this repository in Azure Devops?")
disable = input("please select y/n: ")
if disable == 'y':
pat = 'example'
authorization = str(base64.b64encode(bytes(':' + pat, 'ascii')), 'ascii')
headers = {
'Authorization': 'basic '+authorization
}
organization = "exmaple"
disable_payload = '{"isDisabled": true }'
disable_url = requests.patch(f"https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{i}?api-version=7.1-preview.1",
data=disable_payload)
disable_url.raise_for_status()
print("Repo has been disabled")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
