Sample Signature Code (Python)

This following is Python sample code for generating signatures:

import hashlib
import base64
import urllib

class ooyala_api(object):

    def generate_signature(self, secret_key, http_method, request_path, query_params, request_body=''):
        signature = secret_key + http_method.upper() + request_path
        for key, value in query_params.iteritems():
            signature += key + '=' + value
        signature = base64.b64encode(hashlib.sha256(signature).digest())[0:43]
        signature = urllib.quote_plus(signature)
        return signature

# Example usage of the generate_signature function: 
# Example URL :
#new_ooyala_api = ooyala_api()
#query_params = {'api_key': '7ab06', 'expires': '1299991855'}
#print new_ooyala_api.generate_signature('329b5b204d0f11e0a2d060334bfffe90ab18xqh5', 'get', '/v2/players/HbxJKM', query_params)

해당 내용이 도움 되었습니까?