1. 程式人生 > >訪問圖靈機器人接口請求數據

訪問圖靈機器人接口請求數據

userinfo intent type values 限制 motion on() 訪問 sts

# Third-party Library
import requests

# POST請求參數
args = {
    "reqType": 0,
    "perception": {
        "inputText": {
            "text": "北京"
        }
    },
    "userInfo": {
        "apiKey": "eaf3daedeb374564bfe9db10044bc20b",
        "userId": "6789"
    }
}

# 圖靈機器人API接口
url = "
http://openapi.tuling123.com/openapi/api/v2" res = requests.post(url, json=args) print(res) # <Response [200]> print(res.json().get(results)[0].get(values).get(text)) """ { ‘emotion‘: { ‘robotEmotion‘: { ‘a‘: 0, ‘d‘: 0, ‘emotionId‘: 0, ‘p‘: 0 }, ‘userEmotion‘: { ‘a‘: 0, ‘d‘: 0, ‘emotionId‘: 0, ‘p‘: 0 } }, ‘intent‘: { ‘actionName‘: ‘‘, ‘code‘: 10004, ‘intentName‘: ‘‘ }, ‘results‘: [{ ‘groupType‘: 0, ‘resultType‘: ‘text‘, ‘values‘: { ‘text‘: ‘怎麽老是一句話!‘ } }] }
""" # {‘intent‘: {‘code‘: 4003}, ‘results‘: [{‘groupType‘: 0, ‘resultType‘: ‘text‘, ‘values‘: {‘text‘: ‘請求次數超限制!‘}}]} text = res.json().get("results")[0].get("values").get("text")

訪問圖靈機器人接口請求數據