0
votes

I'm trying to create connection to tfs using python TFSAPI, the tfs is local "http://*...:8080/tfs/default_Collection/Default and i'm getting this error requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: the credentials are right, they work for simple login tried this:

from tfs import TFSAPI
client = TFSAPI(path, user = user, password = password)
workitem = client.get_workitem(100) # Test connection with Workitem id

then like this

import requests
from requests_ntlm import HttpNtlmAuth
username = ' '
password = " "
tfsApi = path
tfsResponse = requests.get(tfsApi,auth=HttpNtlmAuth(username,password))

both end up with same error Traceback (most recent call last): File "", line 1, in File "C:\Users\ohad-ar\AppData\Local\Continuum\anaconda3\lib\site-packages\requests\models.py", line 940, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: any suggestions are welcomed, including a different way to connect tfs api using python Thanks very much

1
it worked with personal access token, docs.microsoft.com/en-us/azure/devops/organizations/accounts/…. Thankstrigonom

1 Answers

1
votes
from tfs import TFSAPI
personalAccessToken = "privetPersonalAccessToken"
path = "http://111.11.11.11:8080/tfs/HRCM_Collection/"
client = TFSAPI(path, pat=personalAccessToken ,project = "DefaultProject")
workitemId = 130000
workitem = client.get_workitem(workitemId )

this worked for me, to get the personal access token use
https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=azure-devops&tabs=preview-page