TFS Rest Api authorization issue in Python 2
<p>I am trying to access <code>TFS</code> REST API in <code>Python</code> 2 but getting <code>401 Authorization Error</code>. I am able to access API url from <code>web-browser</code> using same credentials. Also same credentials is working with <code>.Net</code> code. Tried with urllib2 library as guided in <a href="https://stackoverflow.com/a/8811319/1838307">this solution</a>. Any suggestion to access TFS api in Python2?</p>

<p><strong>tfs.py</strong></p>

<pre><code>import requests
from requests.auth import HTTPDigestAuth

username = '&lt;UserName&gt;'
password = '&lt;Password&gt;'
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()
</code></pre>

<p><strong>Error:</strong></p>

<pre><code>Traceback (most recent call last):
  File "D:\Scripts\tfs.py", line 13, in &lt;module&gt;
    tfsResponse.raise_for_status()
  File "C:\Python27\lib\site-packages\requests\models.py", line 862, in raise_fo
r_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://{myserver}/tfs/collectionName/_apis/projects?api-version=2.0
</code></pre>

<p>.Net Working code:</p>

<pre><code>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))));
</code></pre>