Python Requests vs Curl Requests on Mac Terminal to Fetch Code Content via Github API
<p>I want to get the decrypted content of a code file in a Jquery project on Github. If I do curl request, the returned code content is decrypted. </p>

<p>But using the same parameter on Python requests, the encrypted exists. Why is that and what can I do to get the decrypted version? </p>

<p>Here's my curl command:</p>

<pre><code>curl https://api.github.com/repos/jquery/jquery/git/blobs/1d2872e34a809a9469ac5cb149a40fc7b8007633 -H "Accept: application/vnd.github-blob.raw"
</code></pre>

<p>The output is the following: </p>

<pre><code>&lt;?php
    # Load and run the test suite as a proper XHTML page
    header("Content-type: application/xhtml+xml");
    readfile("index.html");
?&gt;
</code></pre>

<p>Here's my python code: </p>

<pre><code>import requests

code = requests.get('https://api.github.com/repos/jquery/jquery/git/blobs/1d2872e34a809a9469ac5cb149a40fc7b8007633'\
                          ,headers={'content-type':'application/vnd.github-blob.raw'})

code.json()
</code></pre>

<p>The output is this:</p>

<pre><code>{'content': 'PD9waHAKCSMgTG9hZCBhbmQgcnVuIHRoZSB0ZXN0IHN1aXRlIGFzIGEgcHJv\ncGVyIFhIVE1MIHBhZ2UKCWhlYWRlcigiQ29udGVudC10eXBlOiBhcHBsaWNh\ndGlvbi94aHRtbCt4bWwiKTsKCXJlYWRmaWxlKCJpbmRleC5odG1sIik7Cj8+\nCg==\n',
 'encoding': 'base64',
 'sha': '1d2872e34a809a9469ac5cb149a40fc7b8007633',
 'size': 136,
 'url': 'https://api.github.com/repos/jquery/jquery/git/blobs/1d2872e34a809a9469ac5cb149a40fc7b8007633'}
</code></pre>

<pre><code>&gt;&gt;&gt; import base64
&gt;&gt;&gt; base64.b64decode('PD9waHAKCSMgTG9hZCBhbmQgcnVuIHRoZSB0ZXN0IHN1aXRlIGFzIGEgcH
Jv\ncGVyIFhIVE1MIHBhZ2UKCWhlYWRlcigiQ29udGVudC10eXBlOiBhcHBsaWNh\ndGlvbi94aHRtbC
t4bWwiKTsKCXJlYWRmaWxlKCJpbmRleC5odG1sIik7Cj8+\nCg==')
'&lt;?php\n\t# Load and run the test suite as a proper XHTML page\n\theader("Conten
t-type: application/xhtml+xml");\n\treadfile("index.html");\n?&gt;\n'
&gt;&gt;&gt;
</code></pre>

<p>alternatively send the same header that you use with the curl command...</p>

<pre><code>&gt;&gt;&gt; requests.get('https://api.github.com/repos/jquery/jquery/git/blobs/1d2872e34
a809a9469ac5cb149a40fc7b8007633',headers={"Accept": "application/vnd.github-blob
.raw"}).text
u'&lt;?php\n\t# Load and run the test suite as a proper XHTML page\n\theader("Conte
nt-type: application/xhtml+xml");\n\treadfile("index.html");\n?&gt;\n'
&gt;&gt;&gt;
</code></pre>

<p>notice the key is "Accept" ... not "content-type"</p>

python curl github