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

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

猜你喜欢

转载自www.cnblogs.com/apollo1616/p/10273938.html