我试图访问Python
2中的TFS
restapi,但是得到了401 Authorization Error
。我可以使用相同的凭据从web-browser
访问API url。同样的凭证也适用于.Net
代码。尝试按this solution中的指导使用urllib2库。有什么建议在Python2中访问TFS api?在
tfs.py公司
import requests
from requests.auth import HTTPDigestAuth
username = '<UserName>'
password = '<Password>'
tfsApi = 'https://{myserver}/tfs/collectionName/_apis/projects?api-version=2.0'
tfsResponse = requests.get(tfsApi, auth=(username, password))
if(tfsResponse.ok):
tfsResponse = tfsResponse.json()
print(tfsResponse)
else:
tfsResponse.raise_for_status()
错误:
^{pr2}$.Net工作代码:
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",
Convert.ToBase64String(
System.Text.ASCIIEncoding.ASCII.GetBytes(
string.Format("{0}:{1}", AppConfig.TFS_API_USER, AppConfig.TFS_API_PASS))));
TFS使用NTLM authentication protocol,因此我必须使用requests库用httpntlm身份验证更新代码。在
工作代码:
-
请确保已为TFS启用基本身份验证:
相关问题 更多 >
编程相关推荐