Created
April 10, 2015 17:17
-
-
Save Averroes/4e1f066f99ca8b10ddf3 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 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