Created
July 28, 2013 03:16
-
-
Save omo/6097221 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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