2016-09-22 109 views
0

我想在Github的Jquery项目中获取代码文件的解密内容。如果我做了curl请求,则返回的代码内容将被解密。Python请求与Mac上的Curl请求通过Github API获取代码内容

但是,在Python请求中使用相同的参数时,存在加密。为什么是这样,我能做些什么来获得解密版本?

这里是我的curl命令:

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

输出如下:

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

这里是我的Python代码:

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() 

输出是这样的:

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

回答

2
>>> import base64 
>>> base64.b64decode('PD9waHAKCSMgTG9hZCBhbmQgcnVuIHRoZSB0ZXN0IHN1aXRlIGFzIGEgcH 
Jv\ncGVyIFhIVE1MIHBhZ2UKCWhlYWRlcigiQ29udGVudC10eXBlOiBhcHBsaWNh\ndGlvbi94aHRtbC 
t4bWwiKTsKCXJlYWRmaWxlKCJpbmRleC5odG1sIik7Cj8+\nCg==') 
'<?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' 
>>> 

或者发送您curl命令使用相同的头......

>>> requests.get('https://api.github.com/repos/jquery/jquery/git/blobs/1d2872e34 
a809a9469ac5cb149a40fc7b8007633',headers={"Accept": "application/vnd.github-blob 
.raw"}).text 
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' 
>>> 

通知关键是“接受” ......不是“内涵式”

+0

谢谢Joran为更正。 – MLhacker