Skip to content

Instantly share code, notes, and snippets.

@Hyunho
Created December 11, 2013 06:13
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 Hyunho/7905793 to your computer and use it in GitHub Desktop.
Save Hyunho/7905793 to your computer and use it in GitHub Desktop.
clone
"""
This is clone of requests python package
if server is inconvenience to install python package, I want to use this
"""
import urllib2
import urllib
try:
import json
except ImportError:
import simplejson as json
def post(url, data):
if type(data) == str:
req = urllib2.Request(url=url, data=data)
if type(data) == dict:
req = urllib2.Request(url=url, data=urllib.urlencode(data))
f = urllib2.urlopen(req)
return Response(f.read())
class Response:
def __init__(self, content):
self.content = content
def json(self):
return json.loads(self.content)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment