nipkip nipkip - 8 months ago 75
Python Question

How do I pass my subscription key without putting it through terminal?

So on the python sdk for speaker recognition using Microsoft cognitive on the CreateProfile.py I set my subscription key under the variable

subscritionKey
(note: the value set to the variable on this example isn't my actual product key) But when I place it into the one of the parameters for the function
create_profile
I get the error...

Exception: Error creating profile: {"error":{"code":"Unspecified","message":"Access denied due to invalid subscription key. Make sure you are subscribed to an API you are trying to call and provide the right key."}}


Is there I can pass my subscritionKey without having to input it constantly through terminal each time?

import IdentificationServiceHttpClientHelper
import sys

subscritionKey = "j23h4i32h4iu3324iu234h233b43"

def create_profile(subscription_key, locale):
"""Creates a profile on the server.
Arguments:
subscription_key -- the subscription key string
locale -- the locale string
"""
helper = IdentificationServiceHttpClientHelper.IdentificationServiceHttpClientHelper(
subscription_key)

creation_response = helper.create_profile(locale)

print('Profile ID = {0}'.format(creation_response.get_profile_id()))

if __name__ == "__main__":
if len(sys.argv) < 2:
print('Usage: python CreateProfile.py <subscription_key>')
print('\t<subscription_key> is the subscription key for the service')
#sys.exit('Error: Incorrect Usage.')

create_profile(subscritionKey, 'en-us')


My guess is that I'm getting issues because I'm passing it as a string :/

Answer Source

Your question is basically how to consume the SDK, right?

The following code works for me: In a file called main.py that is one level out of the folder Identification:

import sys
sys.path.append('./Identification')
from CreateProfile import create_profile

subscriptionKey = "<YOUR-KEY>"

create_profile(subscriptionKey, "en-us")

Running python main.py (with Python 3), that code returns

Profile ID = cf04bf79-xxxx-xxxxx-xxxx
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download