zoukankan      html  css  js  c++  java
  • Python 调用图灵机器人 API

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

    第四行的 apikey 可能已经失效

  • 相关阅读:
    数据库连接池
    一致性hash
    java 集合大家族
    linkedlist
    HashMap
    hashcode
    Job 逻辑执行图
    CDN
    网站缓存
    Mysql临时文件目录控制
  • 原文地址:https://www.cnblogs.com/justsong/p/8342014.html
Copyright © 2011-2022 走看看