2013-08-25 31 views
1

我有Python代码转换使用github API降价。在Python 3中发送Github Markdown API请求与urllib得到BadStatusLine

gfm.py(蟒蛇3码)以下使用

import traceback 
import json 
import urllib.request 
import http.client 
import sys 

try: 
    content = open(sys.argv[1], 'r').read() 
    data = {"text": content,"mode": 'gfm'} 
    headers = {'Content-Type': 'application/json'} 
    bytes = json.dumps(data).encode('utf-8') 
    url = "https://api.github.com/markdown" 

    request = urllib.request.Request(url, data=bytes, headers=headers) 
    result = urllib.request.urlopen(request).read().decode('utf-8') 
    print(result) 
except http.client.BadStatusLine: 
    traceback.print_exc() 
except: 
    traceback.print_exc() 

脚本和测试降价文件都包含在这里:(例如,在要点gfm.py Sample.mdhttps://gist.github.com/xpol/6332952

当转换小降价文件,它得到了很好的结果。

当转换大型减价文件(例如gfm.py Cheatsheet.md的要点)时,在urllib.request.urlopen行处获得http.client.BadStatusLine: ''

任何人都知道这有什么问题吗? 非常感谢!

+0

任何人都可以提供帮助吗? – xpol

回答

0

我不能重现这一点,但我会建议不管你使用类似python的请求,甚至是一个API封装器列表in the GitHub API docs