Python requests and instagram
<p>I am playing around with the instagram api and requests, trying to get past the OAuth. I use <code>r = requests.get(...)</code> and follow the instagram doc. However, the output from requests is never what I expect. I am having 2 issues that are somewhat similar.</p>

<p>1) If I send the wrong parameters I expect to get back JSON looking like</p>

<pre><code>{"code": 400, "error_type": "OAuthException", "error_message": "You must include a valid client_id, response_type, and redirect_uri parameters"}
</code></pre>

<p>Which is what I see if I paste the string from <code>r.url</code> into the browser. However <code>r.json()</code> simply fails and gives me</p>

<pre><code>JSONDecodeError: Expecting value: line 1 column 1 (char 0)
</code></pre>

<p>2) A correct response should redirect me to my redirect url, which will also include a code. Again, this works correctly when pasting <code>r.url</code> into a browser. I am successfully redirected as expected. Requests does not appear to redirect me, even with explicitly set <code>allow_redirects=False</code>. I only need to read the code from the url. How can I get requests to give me the final url for me to extract the code?</p>

<p>Edit: Might as well include some code.</p>

<pre><code>def get_code(client_id, redirect_uri, scope="basic"):
    params = {"client_id": client_id,
              "redirect_uri": redirect_uri,
              "response_type": "code",
              "scope": scope}
    r = requests.get('https://api.instagram.com/oauth/authorize/',
                     params=params)
    # print r.url
    # print r.json()
    return r
</code></pre>