Created
May 29, 2016 12:57
-
-
Save silviud/3aae4c7ef08bd7d3634d06dd27b2fcf2 to your computer and use it in GitHub Desktop.
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
| import requests | |
| import time | |
| import hashlib | |
| import sys | |
| import hmac | |
| import logging | |
| try: # for Python 3 | |
| from http.client import HTTPConnection | |
| except ImportError: | |
| from httplib import HTTPConnection | |
| HTTPConnection.debuglevel = 1 | |
| logging.basicConfig() # you need to initialize logging, otherwise you will not see anything from requests | |
| logging.getLogger().setLevel(logging.DEBUG) | |
| requests_log = logging.getLogger("requests.packages.urllib3") | |
| requests_log.setLevel(logging.DEBUG) | |
| requests_log.propagate = True | |
| def get(): | |
| path_and_query = "/?TIMESTAMP="+str(int(time.time()))+"&ACCOUNT_ID=admin" | |
| host = "http://localhost:5000" | |
| sig=hmac.new("secret", digestmod=hashlib.sha1, msg=path_and_query).hexdigest() | |
| req = requests.get(host+path_and_query, headers={'X-Auth-Signature': sig}) | |
| print req.content | |
| def post(): | |
| path_and_query = "/?TIMESTAMP="+str(int(time.time()))+"&ACCOUNT_ID=admin" | |
| host = "http://localhost:5000" | |
| sig=hmac.new("secret", digestmod=hashlib.sha1, msg=path_and_query).hexdigest() | |
| req = requests.post(host+path_and_query, headers={'X-Auth-Signature': sig}, data={'n': '1'}) | |
| print req.content | |
| def put(): | |
| path_and_query = "/?TIMESTAMP="+str(int(time.time()))+"&ACCOUNT_ID=admin" | |
| host = "http://localhost:5000" | |
| sig=hmac.new("secret", digestmod=hashlib.sha1, msg=path_and_query).hexdigest() | |
| req = requests.put(host+path_and_query, headers={'X-Auth-Signature': sig}, data={'n': '1'}) | |
| print req.content | |
| if __name__ == '__main__': | |
| if len(sys.argv) > 1: | |
| method = sys.argv[1] | |
| if method == 'post': | |
| post() | |
| elif method == 'get': | |
| get() | |
| elif method == 'put': | |
| put() | |
| else: | |
| print "NA" | |
| else: | |
| print "get|put|post" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment