Python Gets JSON Response As Single Value Dict
<p>Using python to send json requests to a rest api. The initial request is to login! The login, when successful, returns a key to be used with every subsequent request. Login server is down at this very moment, so I've modified my code just as an example to show the issue I face.</p>

<pre><code> #!/usr/bin/env python

import requests
from requests.auth import HTTPDigestAuth
import json

r = requests.get('myApi')
data = json.loads(r.content)
print(r.status_code)

for key, value in data.items():
    print key
    print value

apikey = data['startRow']
</code></pre>

<p>The output is;</p>

<pre><code>401
response
{u'status': 401, u'startRow': 0, u'totalRows': 1, u'data': {u'errors': [u'Credentials are not valid']}, u'endRow': 1}

Traceback (most recent call last):
  File "zzzz\test.py", line 24, in &lt;module&gt;
    apikey = data['startRow']
KeyError: 'startRow'
</code></pre>

<p>How can a specific param in the dict be referenced? It <em>appears</em> as though the value is actually the whole response itself is the value, and not startRow or errors, etc. </p>