Skip to content

Instantly share code, notes, and snippets.

@ericxyan
Created April 26, 2016 19:33
Show Gist options
  • Save ericxyan/69c4263329bd13d900ad84fd83d47d8a to your computer and use it in GitHub Desktop.
Save ericxyan/69c4263329bd13d900ad84fd83d47d8a to your computer and use it in GitHub Desktop.
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