Python 调用图灵机器人 API

时间:2023-03-09 04:25:54
Python 调用图灵机器人 API
 ''' Python3'''
import requests #导入requests库
import json #导入json库
key = '3119f1e3610f42c5977ea73c4097cb1c' # 单引号里写你注册的的图灵机器人apikey
while True: #主循环
info = input('\n我:') #输入对话信息
url = 'http://www.tuling123.com/openapi/api?key='+key+'&info='+info # 拼接 url
res = requests.get(url) # 得到数据
res.encoding = 'utf-8' # 防止中文乱码
data = json.loads(res.text) # 将得到的 json 格式的信息转换为 Python 的字典格式
print('\nBot: '+data['text']) # 输出结果

第四行的 apikey 可能已经失效