Last active
December 18, 2015 03:39
-
-
Save sentenza/5719857 to your computer and use it in GitHub Desktop.
Simple Python REST client See also https://github.com/scastillo/siesta
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
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