Skip to content

Instantly share code, notes, and snippets.

@Dice64
Created August 4, 2013 11:14
Show Gist options
  • Save Dice64/6150064 to your computer and use it in GitHub Desktop.
Save Dice64/6150064 to your computer and use it in GitHub Desktop.
Requests AuthBase for signing requests to dice64.com
from requests.auth import AuthBase
class Dice64Auth(AuthBase):
def __init__(self, userid, sign_key):
self.userid = userid
self.sign_key = sign_key
def __call__(self, r):
r.headers['Authorization'] = "BTC %d:%s" % (self.userid, self.get_signature(r))
return r
def get_signature(self, r):
parsedurl = urlparse(r.url)
if r.method == 'GET' and parsedurl.query == '':
message = r.method + ' ' + parsedurl.path + '\n\n'
elif r.method == 'GET' and parsedurl.query != '':
message = r.method + ' ' + parsedurl.path + '?' + parsedurl.query + '\n\n'
else:
message = r.method + ' ' + parsedurl.path + '\n\n' + r.body
signature = bitcoinsign.sign_message(self.sign_key, message)
return signature
# Call using the userid of the account and the private sign_key to sign the message
payload = {'nonce': nonce, 'secret_hash': secret_hash, 'below': below, 'amount': bet_amount, 'multiplier': multiplier}
r = requests.post(URL + '/api/account/bet', data=payload, auth=Dice64Auth(userid, sign_key))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment