0

I m running below code to fetch to get Odata query but getting auth error

import requests
import json
endpoint_url = "https://analytics.dev.azure.com/pbi0280/TestOdata/_odata/v4.0-preview/WorkItems?$select=WorkItemId,WorkItemType,Title,State"
pat = "vch3ufmtbnimclfumrms5vgulcktrtakhp2hig3p7v3cs3ormi7q"
headers = {"Authorization": "Bearer " + pat}
response = requests.get(endpoint_url, headers=headers)
data = json.loads(open(response.text,encoding='utf-8-sig'))
print(data)

Error : No such file or directory: '\ufeff{"$id":"1","innerException":null,"message":"TF400813: The user 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa' is not authorized to access this resource.","typeName":"Microsoft.TeamFoundation.Framework.Server.UnauthorizedRequestException, Microsoft.TeamFoundation.Framework.Server","typeKey":"UnauthorizedRequestException","errorCode":0,"eventId":3000}'

When I m running same url in web, its working fine and json output.

enter image description here

1
  • 1
    You should never ask questions with sensitive information into them. You've published your PAT and Azure DevOps organization and project. You should immediately revoke the PAT to safe guard your environments. Commented Jan 31, 2023 at 17:55

1 Answer 1

0

Azure DevOps does not support Authorization: Bearer with personal access tokens (PAT). They must be supplied using basic authentication. The user name can be left blank but the PAT must be supplied as the password.

Switch over to basic authentication and your code should work fine.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.