Created
April 10, 2015 17:16
-
-
Save Averroes/5cc08c24a238e4624da6 to your computer and use it in GitHub Desktop.
interacting with http services as a client
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
| # A basic GET request | |
| from urllib import request, parse | |
| # Base URL being accessed | |
| url = 'http://httpbin.org/get' | |
| # Dictionary of query parameters (if any) | |
| parms = { | |
| 'name1' : 'value1', | |
| 'name2' : 'value2' | |
| } | |
| # Encode the query string | |
| querystring = parse.urlencode(parms) | |
| # Make a GET request and read the response | |
| u = request.urlopen(url+'?' + querystring) | |
| resp = u.read() | |
| import json | |
| from pprint import pprint | |
| json_resp = json.loads(resp.decode('utf-8')) | |
| pprint(json_resp) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment