devopshq / tfs

Microsoft TFS API Python client
https://devopshq.github.io/tfs/
MIT License
110 stars 28 forks source link

Project items are removed from the url when calling TFSAPI #55

Open rtc116 opened 5 years ago

rtc116 commented 5 years ago

I am specifying a Collection as well as a Project in the call to TFSAPI, however when I try to retrieve a work item there is a HTTPError: 401 Client Error: Unauthorized for url...However, I noticed that the project has been removed from the url and this could be causing the authentication error. call to TFSAPI:

client = TFSAPI("https://tfsserver:8080/tfs/", project="CollectionName/ProjectName", user=user, password=password, auth_type=HttpNtlmAuth) workitem = client.get_workitem(10) Error: ...requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://tfsserver:8080/tfs/CollectionName/_apis/wit/workitems?ids=10&$expand=all&api-version=1.0

SAnCherepan commented 5 years ago

AFAIK, project is not required for retrieving work items. Try the link you provided in your web browser and see if you get JSON data or 401 error,

To help with your issue we might need some extra details: 1) what TFS version are you using? 2) are you using password or personal access token when initializing TFSAPI?

rtc116 commented 5 years ago

I am using TFS 2018.2. The TFS module defaults to version=1.0 of the API which should work. I guess I could change the TFSAPI module code to change this, unless I can send the API version as an argument. I'm still curious why the Project is chopped from the url, and only the Collection name remains. Currently I am awaiting feedback from my organization about permissions on the collection.

rtc116 commented 5 years ago

Also, when I paste the url to the web browser the following error is displayed - "Work item 10 does not exist, or you do not have permissions to read it."

Boltyk commented 5 years ago

@rtc116 401 means wrong user/password or personal access token. In my case I was unable to make it work with my user/password, but access token works well. Work Item ID also supposed to be valid You can generate user access token by yourself - https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts

Boltyk commented 5 years ago

I believe this is not an issue. Work items api don't have project name in the url.

https://docs.microsoft.com/en-us/azure/devops/integrate/previous-apis/wit/work-items?view=tfs-2015#get-a-work-item

SAnCherepan commented 5 years ago

Also, when I paste the url to the web browser the following error is displayed - "Work item 10 does not exist, or you do not have permissions to read it."

@rtc116, then it is not the library's, issue.

  1. Make sure Work Item 10 exists. Or use any other WI that exists.
  2. Make sure the account you use for the API has access rights and can see that WI in the web browser without any errors.

Only then will you be able to see if the library actually works or not. Let us know if you have any problem after these steps.