尝试连接到TFSAPI时出现错误401

时间:2020-02-11 06:18:03

标签: python tfs

我正在尝试使用python TFSAPI建立与tfs的连接, tfs是本地的“ http:// *。:8080 / tfs / default_Collection / Default 而我得到这个错误 requests.exceptions.HTTPError:401客户端错误:未经授权的网址: 凭据是正确的,它们可用于简单登录 尝试了这个:

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

然后这样

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

都以相同的错误结尾 回溯(最近通话最近): 文件“”,第1行,位于 在“ c:\ Users \ ohad-ar \ AppData \ Local \ Continuum \ anaconda3 \ lib \ site-packages \ requests \ models.py”文件中,第940行,位于raise_for_status中 引发HTTPError(http_error_msg,response = self) requests.exceptions.HTTPError:401客户端错误:未经授权的网址: 欢迎任何建议,包括使用python连接tfs api的不同方法 非常感谢

1 个答案:

答案 0 :(得分:0)

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 )

这对我有用, 获取个人访问令牌的用途
https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=azure-devops&tabs=preview-page