# api尝试:聊天机器人

api尝试:聊天机器人

相关配置:

python:3.8
模块:itchat

尝试过程:

  1. 安装itchat
    https://blog.csdn.net/qq_37482202/article/details/84145028
import itchat
itchat.auto_login(hotReload=True)

报错:

█
Getting uuid of QR code.
Downloading QR code.
Please scan the QR code to log in.
Please press confirm on your phone.
Your wechat account may be LIMITED to log in WEB wechat, error info:
<error><ret>1203</ret><message>为了你的帐号安全,此微信号不能登录网页微信。你可以使用Windows微信或Mac微信在电脑端登录。Windows微信下载地址:https://pc.weixin.qq.com  Mac微信下载地址:https://mac.weixin.qq.com</message></error>
>>> 

应该是这个功能被微信禁止了,但没关系,我要的主要还是python本地的聊天机器人,所以跳过这一步

  1. 先注意图灵
    http://www.tuling123.com

注册成功!说是新用户可以有每日免费数量

  1. 调用api
url="http://www.tuling123.com/openapi/api"
key="720b8495c39f40ac92284c5d6b3d1dd7"
msg="你好漂亮"
userid="100000"
data={
    'key':key,
    'info':msg,
    'userid':userid
}
repson=requests.post(url,data=data).json()
print(repson.get("text"))

报错:NameError: name ‘requests’ is not defined
之前解决过这种问题,不太记得了,那就再来一遍!

  1. 尝试添加import requests
    测试成功!那改成自己的key试试

  2. 改成自己的key后
    回复:请按规定的要求进行加密

只能去看看文档了:
https://www.kancloud.cn/turing/www-tuling123-com/718218

找了半天,也没找到userid,问题没找到解决方案,暂时还是用原作者的key和id了

  1. 结果有次数限制:
说点什么:你好
亲爱的,当天请求次数已用完。
说点什么:
  1. 再试试自己的帐户吧
{
	"reqType":0,
    "perception": {
        "inputText": {
            "text": "附近的酒店"
        },
        "inputImage": {
            "url": "imageUrl"
        },
        "selfInfo": {
            "location": {
                "city": "北京",
                "province": "北京",
                "street": "信息路"
            }
        }
    },
    "userInfo": {
        "apiKey": "",
        "userId": ""
    }
}

结果还是没找到,尝试看看在百度有没有吧

  1. 问度娘了下:
    https://blog.csdn.net/hhmy77/article/details/94627986

看到这里有个青云客:
http://api.qingyunke.com/

试一下:
结果:

requests.post('http://api.qingyunke.com/api.php?key=free&appid=0&msg=你好')

这个不报错
但用这种方式就报错了:

url="http://api.qingyunke.com/api.php"
    key="free"
    appid=0
    msg="你好"
    data={
        'key':key,
        'msg':msg,
        'appid':appid
    }
    repson=requests.post(url,data).json()

先了解一下requests.post的原理吧

  1. 试一下这种方法:
    https://www.cnblogs.com/android-it/p/9558751.html
url_json = 'http://httpbin.org/post'
data_json = json.dumps({'key1':'value1','key2':'value2'})   #dumps:将python对象解码为json数据
r_json = requests.post(url_json,data_json)
print(r_json)
print(r_json.text)
print(r_json.content)

测试了还是不行

  1. 暂时讲究一下:
repson=requests.post(url+'key=free&appid=0&msg='+str).json()

用这个方式虽然不好看,但有效,有空了解下post吧!

回头,就完成聊天机器人和语音播放的融合吧!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值