Hello Joseph Choi,
Thanks for raising this question in the Q&A forum! 401 Unauthorized in Azure DevOps Server (on-premise) typically stems from incorrect PAT encoding, insufficient permissions, or authentication method mismatches. On-premise servers require Basic Auth with Base64-encoded PAT (not plain PAT).
Quick Fix: Correct PAT Encoding
Azure DevOps Server requires PAT prepended with colon before Base64 encoding:
python
import
Common 401 Causes & Fixes
| Issue |
Solution |
| Missing colon prefix |
Encode :{PAT} not just {PAT} |
| -------- |
-------- |
| Missing colon prefix |
Encode :{PAT} not just {PAT} |
| Wrong auth type |
Use Basic not Bearer |
| Insufficient PAT scopes |
Regenerate PAT with required permissions |
| Organization-level API |
Requires Project Collection Admin role |
| Cached credentials |
Clear browser cache/use incognito |
Verify PAT Permissions
On-premise Server PAT creation:
Server URL → User Settings → Security → Personal access tokens
Click New Token
Select required scopes (Code: Read/Write, Work Items: Read/Write)
Set expiration (max 1 year for on-premise)
Copy token immediately (shown only once)
Test Authentication
bash
# PowerShell - Windows
bash
# curl - Linux/Mac
On-Premise Specific Issues
- IIS Authentication: Ensure Anonymous Authentication enabled in IIS for REST API endpoints
- Windows Auth conflict: Disable Windows Authentication if using PAT
- API version: Use
api-version=6.0 or 5.0 for Server 2020/2019 (not 7.x)
- Collection path: Include
/tfs/CollectionName/ in URL (not just /)
Debugging Steps
Test PAT in browser: https://:{PAT}@your-server.com/tfs/DefaultCollection/_apis/projects
Check server logs: C:\Program Files\Azure DevOps Server 2022\Application Tier\Web Services\_tfs_data\Logs
Verify account: Navigate to https://your-server.com/tfs/_admin/_security
- Confirm collection access: User must be in Project Collection Valid Users
Alternative: Alternate Authentication
If PAT fails, use NTLM/Negotiate (Windows environments):
python
import
If helpful, kindly accept the answer.
Cheers,
Jerald Felix