If you don't find an answer, please click here to post your question.
Reply
Highlighted
Occasional Contributor
Posts: 8
Registered: ‎08-16-2017
Accepted Solution

Invalid signature for v3 API with python

I would like to use a python script to retrieve data from the v3 analytics API.

So I tried to use this sample signature generation code: http://help.ooyala.com/video-platform/api/signature_python.html

Along with the example code from post 3 here: http://community.ooyala.com/t5/Developers-Forum/v3-API-Signature-with-python/td-p/8037

And I am getting "invalid signature" when I try to send a GET request with curl using the resulting string as follows

curl -X GET "<string output from gen_request.py>"

 

Any thoughts on what I am doing wrong? The python code I am using is below:

ooyala_api.py:

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

 gen_request.py

import datetime
import urllib
from ooyala_api import ooyala_api

api_key = 'insertapikey'
secret = 'insertsecret'
method = 'GET'
path = '/v3/analytics/reports'
expires = (datetime.datetime.now() + datetime.timedelta(days=1)).strftime('%s')
params = {
  'api_key': api_key,
  'expires': expires,
  'report_type': 'performance',
  'start_date': '2017-02-01',
  'end_date': '2017-08-12',
  'dimensions': 'asset',
  'metrics': 'displays',
  'limit': '500'
}

api = ooyala_api()
signature = api.generate_signature(secret, method, path, params)
query_string = urllib.urlencode(params)
request_uri = 'https://api.ooyala.com' + path + '?' + query_string + '&signature=' + signature
print request_uri

Accepted Solutions
Ooyalan
Posts: 12
Registered: ‎05-08-2017

Re: Invalid signature for v3 API with python

Hello redpine.

 

First, on the generate_signature function (inside of ooyala_api.py), you have the following line:

for key, value in query_params.iteritems():

The values must be sorted. You should have this:

for key, value in sorted(query_params.iteritems()):

 

 

Also, make sure that the value assigned to the variable "expire" is on epoch format.

expires = (datetime.datetime.now() + datetime.timedelta(days=1)).strftime('%s')

 

For further information please review the following URLs:

 
If you continues having problems or need further investigation, please open a support case, We will gladly assist you.
 
Regards,
Ooyala Technical Support

View solution in original post


All Replies
Ooyalan
Posts: 12
Registered: ‎05-08-2017

Re: Invalid signature for v3 API with python

Hello redpine


I'm looking into this, I'll give you an update tomorrow.

Regards,
Ooyala Technical Support

Ooyalan
Posts: 12
Registered: ‎05-08-2017

Re: Invalid signature for v3 API with python

Hello redpine.

 

First, on the generate_signature function (inside of ooyala_api.py), you have the following line:

for key, value in query_params.iteritems():

The values must be sorted. You should have this:

for key, value in sorted(query_params.iteritems()):

 

 

Also, make sure that the value assigned to the variable "expire" is on epoch format.

expires = (datetime.datetime.now() + datetime.timedelta(days=1)).strftime('%s')

 

For further information please review the following URLs:

 
If you continues having problems or need further investigation, please open a support case, We will gladly assist you.
 
Regards,
Ooyala Technical Support
Occasional Contributor
Posts: 8
Registered: ‎08-16-2017

Re: Invalid signature for v3 API with python

The sorting was indeed the problem - thank you for the fix!

Perhaps this sample signature code should be updated to include that fix?

http://help.ooyala.com/video-platform/api/signature_python.html

Ooyalan
Posts: 12
Registered: ‎05-08-2017

Re: Invalid signature for v3 API with python

Hello redpine,

 

Sure, We'll update the documentation with this information.

 

Regards,

Ooyala Technical Support