apollo1616

访问图灵机器人接口请求数据

# 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")

 

发表于 2019-01-15 19:45  阿波罗Apollo  阅读(1565)  评论(0编辑  收藏  举报
 

分类:

技术点:

相关文章: