Skip to content

Instantly share code, notes, and snippets.

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

  • Save Averroes/4e1f066f99ca8b10ddf3 to your computer and use it in GitHub Desktop.

Select an option

Save Averroes/4e1f066f99ca8b10ddf3 to your computer and use it in GitHub Desktop.
interacting with http services as a client
# A POST request using requests library
import requests
# Base URL being accessed
url = 'http://httpbin.org/post'
# Dictionary of query parameters (if any)
parms = {
'name1' : 'value1',
'name2' : 'value2'
}
# Extra headers
headers = {
'User-agent' : 'none/ofyourbusiness',
'Spam' : 'Eggs'
}
resp = requests.post(url, data=parms, headers=headers)
# Decoded text returned by the request
text = resp.text
from pprint import pprint
pprint(resp.json)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment