API error handling
<p>So, I am using API calls to get some json data, and I am using a for loop to execute the call using multiple ids which will return different data based on the user's id. So basically we need to update the permissions for some of our users so the json data looks somewhat like this for the users without permissions:</p>

<pre><code>{"meta":{"httpStatus":"401 - Unauthorized","error":{"errorMessage":"Insufficient
permissions.","errorCode":"ARH_8.5"},"requestId":null}}
</code></pre>

<p>and this for users with the permissions:</p>

<pre><code>{"result":{"elements":[{"id":"dslkjafsadl","name":"Test","ownerId"
:"sdfadfsfsda","lastModified":"2016","isActive":true},
{"id":"dsafsad","name":"Test","ownerId":"sdfasdfa","lastModified":"2016","isActive":true}],"nextPage":null},"meta":{"httpStatus":"200 - OK","requestId":"3242343"}}
</code></pre>

<p>so my question is if I have a big response with many results both with and without permissions how could I only pull the ids from the users with permissions, and exclude the ones without the permissions.</p>

<p>Say the response is stored in the variable "data" and the ids that I am looking for will be stored in "requestId" this is the code I tried:</p>

<pre><code>requestId = request_id = [element['requestId'] for element in data['result']['elements']]
</code></pre>

<p>from this code I receive the a TypeError, and it doesn't recognize 'result' because the first response is a user without the correct permissions. </p>