1

Possible Duplicate:
Implementaion HMAC-SHA1 in python

`I am attempting to do some OAuth authentication with python, but my oauth_signature keeps getting rejected. Python 3 is pretty new to me, so can someone tell me what is wrong with this code:

api_key = 'string'
api_secret = 'another_string'
sig_key = api_secret + '&' + api_key
hmac_alg = hmac.new(sig_key.encode('utf-8'), sig_base_str.encode('utf-8'),hashlib.sha1)

signature_base = base64.b64encode(hmac_alg.digest())
url = url_base + '?' + 'oauth_signature=' + urllib.parse.quote(str(signature_base.decode('utf-8')),'') + '&' + str(param_str)

param_str is a & delimited string of my input parameters. The HTTP service seems to be reading that fine as it will change the output response based on what i asked for. It just keeps rejecting my signature. I think hmac is the culprit.

Community
  • 1
  • 1
Chris
  • 4,425
  • 5
  • 34
  • 49
  • I think my question lies in converting the pseudocode to python. since hmac doesn't accept strings. – Chris Dec 13 '12 at 12:56

1 Answers1

0

Can you try the following

api_key = b'string'
api_secret = b'another_string'

From python documentation

PEP 3112: Byte Literals. The b"..." string literal notation (and its variants like b'...', b"""...""", and br"...") now produces a literal of type bytes.

srhegde
  • 573
  • 4
  • 3