如何在不通过终端的情况下传递我的订阅密钥?
How do I pass my subscription key without putting it through terminal?
因此,在 python sdk 上使用 Microsoft cognitive 在 CreateProfile.py 上进行说话人识别时,我在变量 subscritionKey
下设置了我的订阅密钥(注意:在此变量上设置的值示例不是我的实际产品密钥)但是当我将它放入函数 create_profile
的参数之一时,我收到错误...
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."}}
是否可以传递我的 subscritionKey 而不必每次都通过终端不断输入它?
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')
我的猜测是我遇到了问题,因为我将它作为字符串传递:/
你的问题基本上是如何使用SDK,对吧?
以下代码对我有用:在一个名为 main.py
的文件中,该文件位于文件夹 Identification
的一层:
import sys
sys.path.append('./Identification')
from CreateProfile import create_profile
subscriptionKey = "<YOUR-KEY>"
create_profile(subscriptionKey, "en-us")
运行python main.py
(带Python3),即代码returns
Profile ID = cf04bf79-xxxx-xxxxx-xxxx
因此,在 python sdk 上使用 Microsoft cognitive 在 CreateProfile.py 上进行说话人识别时,我在变量 subscritionKey
下设置了我的订阅密钥(注意:在此变量上设置的值示例不是我的实际产品密钥)但是当我将它放入函数 create_profile
的参数之一时,我收到错误...
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."}}
是否可以传递我的 subscritionKey 而不必每次都通过终端不断输入它?
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')
我的猜测是我遇到了问题,因为我将它作为字符串传递:/
你的问题基本上是如何使用SDK,对吧?
以下代码对我有用:在一个名为 main.py
的文件中,该文件位于文件夹 Identification
的一层:
import sys
sys.path.append('./Identification')
from CreateProfile import create_profile
subscriptionKey = "<YOUR-KEY>"
create_profile(subscriptionKey, "en-us")
运行python main.py
(带Python3),即代码returns
Profile ID = cf04bf79-xxxx-xxxxx-xxxx