Skip to content

Instantly share code, notes, and snippets.

@omo
Created July 28, 2013 03:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save omo/6097221 to your computer and use it in GitHub Desktop.
Save omo/6097221 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
import os
import json
import urllib
import urllib2
import requests
URL = "https://api.github.com/gists"
#PADDING_SIZE = 1024 # This works
PADDING_SIZE = 2048
def make_body():
body_dict = {
"description": "This Is A Test Data For Reproduction. Feel Free to Delete This.",
"public": False,
"files": {
"hello.md": {
"content": "Hello\n" * PADDING_SIZE
}
}
}
return json.dumps(body_dict)
def post_with_urllib2():
body = make_body()
body = body
req = urllib2.Request(URL, data=body)
req.add_header("Content-Type", "application/json")
res = urllib2.urlopen(req)
res_dict = json.load(res)
return res_dict
def post_with_request():
body = make_body()
return requests.post(URL, headers = {'content-type': 'application/json'}, data = body).json()
# Neither works. It throws a httplib.BadStatusLine exception.
#res = post_with_urllib2()
res = post_with_request()
print res["url"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment