MLhacker MLhacker - 6 months ago 26
Python Question

Python Requests vs Curl Requests on Mac Terminal to Fetch Code Content via Github API

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.

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

Here's my curl command:

curl -H "Accept: application/vnd.github-blob.raw"

The output is the following:

# Load and run the test suite as a proper XHTML page
header("Content-type: application/xhtml+xml");

Here's my python code:

import requests

code = requests.get(''\


The output is this:

{'content': 'PD9waHAKCSMgTG9hZCBhbmQgcnVuIHRoZSB0ZXN0IHN1aXRlIGFzIGEgcHJv\ncGVyIFhIVE1MIHBhZ2UKCWhlYWRlcigiQ29udGVudC10eXBlOiBhcHBsaWNh\ndGlvbi94aHRtbCt4bWwiKTsKCXJlYWRmaWxlKCJpbmRleC5odG1sIik7Cj8+\nCg==\n',
'encoding': 'base64',
'sha': '1d2872e34a809a9469ac5cb149a40fc7b8007633',
'size': 136,
'url': ''}

>>> import base64
>>> base64.b64decode('PD9waHAKCSMgTG9hZCBhbmQgcnVuIHRoZSB0ZXN0IHN1aXRlIGFzIGEgcH
'<?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?>\n'

alternatively send the same header that you use with the curl command...

>>> requests.get('
a809a9469ac5cb149a40fc7b8007633',headers={"Accept": "application/vnd.github-blob
u'<?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?>\n'

notice the key is "Accept" ... not "content-type"