Created
April 26, 2016 19:33
-
-
Save ericxyan/69c4263329bd13d900ad84fd83d47d8a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import httplib2 as http | |
import json | |
try: | |
from urlparse import urlparse | |
except ImportError: | |
from urllib.parse import urlparse | |
headers = { | |
'Accept': 'application/json', | |
'Content-Type': 'application/json; charset=UTF-8' | |
} | |
uri = 'http://yourservice.com' | |
path = '/path/to/resource/' | |
target = urlparse(uri+path) | |
method = 'GET' | |
body = '' | |
h = http.Http() | |
# If you need authentication some example: | |
if auth: | |
h.add_credentials(auth.user, auth.password) | |
response, content = h.request( | |
target.geturl(), | |
method, | |
body, | |
headers) | |
# assume that content is a json reply | |
# parse content with the json module | |
data = json.loads(content) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment