Created
August 15, 2013 20:25
-
-
Save philangist/a967583b949e070105ac to your computer and use it in GitHub Desktop.
This file contains 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 md5 | |
import requests | |
from requests.auth import HTTPBasicAuth | |
class DigestClient(object): | |
def __init__(self, url, username, password): | |
self.url = url | |
self.username = username | |
self.password = password | |
def prep_for_call(self): | |
response = requests.get(self.url + '/nonce') | |
self.nonce = response.text | |
def make_call(self): | |
self.prep_for_call() | |
password_hash = md5.new(self.nonce + self.password) | |
self.password = password_hash.hexdigest() | |
response = requests.get(self.url + '/hello', | |
auth=HTTPBasicAuth( | |
self.username, self.password | |
)) | |
print response.text | |
digest_client = DigestClient( | |
'http://localhost:4000', | |
'phil', | |
'Ill send an SOS to the world' | |
) | |
digest_client.make_call() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment