【发布时间】:2017-03-06 07:37:13
【问题描述】:
我现有的代码是:
import requests
import json
import os
url = "https://stream.watsonplatform.net/speech-to-text-beta/api/v1/recognize"
username= "USERNAME"
password= "PASSWORD"
filepath = '/home/user/myfamily.ogg' # path to file
filename = os.path.basename(filepath)
audio = open(filepath,'rb')
files_input = {
"audioFile":(filename,audio,'audio/ogg')
}
response = requests.post(url, auth=(username, password), headers={"Content-Type": "audio/wav"},files=files_input)
print('stauts_code: {} (reason: {})'.format(response.status_code, response.reason))
print response.text
但是,我收到以下错误: status_code:405(原因:不允许的方法)
{
"error": "Your browser approached me (at /text-to-speech/api) with the method \"POST\". I only allow the methods HEAD, GET here.",
"code": 405,
"code_description": "Method Not Allowed"
}
我使用 .ogg 文件作为音频输入。
【问题讨论】:
-
你试过
response = requests.get(url, ....) -
您可能需要使用
requests.Session对象首次登录(使用post),然后使用get获取您想要的数据。见this answer,到How to “log in” to a website using Python's Requests module?
标签: python ibm-cloud text-to-speech speech-to-text watson