def get_signature(self, uri, method='GET', body=''):
"""Return a dictionary with the API key and API get_signature
to be sent for the given request."""
# What time is it now?
timestamp = timegm(datetime.datetime.now(tz=pytz.UTC).timetuple())
# Calculate the base string to use for the signature.
base_string = unicode(''.join((
self.auth_key.secret,
unicode(timestamp),
method.upper(),
uri,
body,
))).encode('utf-8')
# Return a dictionary with the headers to send.
return {
'HTTP_X_API_KEY': self.auth_key.auth_key,
'HTTP_X_API_SIGNATURE': sha1(base_string).hexdigest(),
'HTTP_X_API_TIMESTAMP': timestamp,
}
评论列表
文章目录