Skip to content

Instantly share code, notes, and snippets.

@Averroes
Created April 10, 2015 17:16
Show Gist options
  • Select an option

  • Save Averroes/5cc08c24a238e4624da6 to your computer and use it in GitHub Desktop.

Select an option

Save Averroes/5cc08c24a238e4624da6 to your computer and use it in GitHub Desktop.
interacting with http services as a client
# 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