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
# there is a problem with the coinbase python example | |
# at https://coinbase.com/docs/api/authentication where they | |
# fail to add the content type header to the POST action | |
# this is the actual implementation | |
def get_http(self, url, body=None): | |
opener = urllib2.build_opener() | |
nonce = int(time.time() * 1e6) | |
message = str(nonce) + url + ('' if body is None else body) | |
signature = hmac.new(settings.COINBASE_API_SECRET, message, hashlib.sha256).hexdigest() | |
opener.addheaders = [('ACCESS_KEY', settings.COINBASE_API_KEY), | |
('ACCESS_SIGNATURE', signature), | |
('ACCESS_NONCE', nonce)] | |
try: | |
response = opener.open(urllib2.Request(url,body,{'Content-Type': 'application/json'})) | |
return response | |
except urllib2.HTTPError as e: | |
print e | |
return e |
No comments:
Post a Comment