mgsky1 / FG

基于Nonebot的QQ群机器人🤖️,特色功能是利用机器学习算法,基于每日聊天记录生成每日总结。可在酷Q/Mirai平台上运行
Apache License 2.0
102 stars 9 forks source link

找不到使用json的ujson模块 #2

Closed byx2020 closed 4 years ago

byx2020 commented 4 years ago

我按照前面的环境要求安装完了依赖(python版本3.8,wordcloud版本1.8.0),但到了最后一步执行python bot.py的时候,出现了报错,提示找不到使用json的ujson模块,以下为报错内容:

ujson module not found, using json
Traceback (most recent call last):
  File "bot.py", line 10, in <module>
    import config
  File "C:\software\Mirai\plugins\FG-mirai\config.py", line 11, in <module>
    configuration = JsonUtils.json2Dict(os.path.join(os.getcwd(),'cn','acmsmu','FG','data','config.json'))
  File "C:\software\Mirai\plugins\FG-mirai\Utils\JsonUtils.py", line 15, in json2Dict
    jsonDict = json.loads(f.read())
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\json\__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\json\decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Invalid control character at: line 29 column 42 (char 629)

我代码水平不行,不过还是想挣扎一下,了解一下是哪里出了错误,有没有解决的办法,麻烦大佬有时间的话可以解答一下,非常感谢

byx2020 commented 4 years ago
C:\software\Mirai\plugins\FG-mirai>pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn -r  requirements.txt
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Requirement already satisfied: aiocache==0.11.1 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 1)) (0.11.1)
Requirement already satisfied: aiocqhttp==1.2.5 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 2)) (1.2.5)
Requirement already satisfied: aiofiles==0.4.0 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 3)) (0.4.0)
Requirement already satisfied: APScheduler==3.6.3 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 4)) (3.6.3)
Requirement already satisfied: astroid==2.3.3 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 5)) (2.3.3)
Requirement already satisfied: beautifulsoup4==4.8.2 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 6)) (4.8.2)
Requirement already satisfied: blinker==1.4 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 7)) (1.4)
Requirement already satisfied: brainyquote==0.2 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 8)) (0.2)
Requirement already satisfied: certifi==2019.11.28 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 9)) (2019.11.28)
Requirement already satisfied: chardet==3.0.4 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 10)) (3.0.4)
Requirement already satisfied: click==7.1.1 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 11)) (7.1.1)
Requirement already satisfied: colorama==0.4.3 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 12)) (0.4.3)
Requirement already satisfied: cycler==0.10.0 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 13)) (0.10.0)
Requirement already satisfied: decorator==4.4.2 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 14)) (4.4.2)
Requirement already satisfied: h11==0.9.0 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 15)) (0.9.0)
Requirement already satisfied: h2==3.2.0 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 16)) (3.2.0)
Requirement already satisfied: hpack==3.0.0 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 17)) (3.0.0)
Requirement already satisfied: hstspreload==2020.3.31 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 18)) (2020.3.31)
Requirement already satisfied: httpx==0.12.1 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 19)) (0.12.1)
Requirement already satisfied: Hypercorn==0.9.4 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 20)) (0.9.4)
Requirement already satisfied: hyperframe==5.2.0 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 21)) (5.2.0)
Requirement already satisfied: idna==2.9 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 22)) (2.9)
Requirement already satisfied: isort==4.3.21 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 23)) (4.3.21)
Requirement already satisfied: itsdangerous==1.1.0 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 24)) (1.1.0)
Requirement already satisfied: jieba==0.42.1 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 25)) (0.42.1)
Requirement already satisfied: Jinja2==2.11.1 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 26)) (2.11.1)
Requirement already satisfied: kiwisolver==1.2.0 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 27)) (1.2.0)
Requirement already satisfied: lazy-object-proxy==1.4.3 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 28)) (1.4.3)
Requirement already satisfied: MarkupSafe==1.1.1 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 29)) (1.1.1)
Requirement already satisfied: matplotlib==3.2.1 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 30)) (3.2.1)
Requirement already satisfied: mccabe==0.6.1 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 31)) (0.6.1)
Requirement already satisfied: networkx==2.4 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 32)) (2.4)
Requirement already satisfied: nonebot==1.5.0 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 33)) (1.5.0)
Requirement already satisfied: numpy==1.18.2 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 34)) (1.18.2)
Requirement already satisfied: Pillow==7.1.1 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 35)) (7.1.1)
Requirement already satisfied: priority==1.3.0 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 36)) (1.3.0)
Requirement already satisfied: pylint==2.4.4 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 37)) (2.4.4)
Requirement already satisfied: pyparsing==2.4.6 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 38)) (2.4.6)
Requirement already satisfied: python-dateutil==2.8.1 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 39)) (2.8.1)
Requirement already satisfied: pytz==2019.3 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 40)) (2019.3)
Requirement already satisfied: Quart==0.11.5 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 41)) (0.11.5)
Requirement already satisfied: requests==2.23.0 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 42)) (2.23.0)
Requirement already satisfied: rfc3986==1.3.2 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 43)) (1.3.2)
Requirement already satisfied: six==1.14.0 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 44)) (1.14.0)
Requirement already satisfied: sniffio==1.1.0 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 45)) (1.1.0)
Requirement already satisfied: soupsieve==2.0 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 46)) (2.0)
Requirement already satisfied: textrank4zh==0.3 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 47)) (0.3)
Requirement already satisfied: toml==0.10.0 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 48)) (0.10.0)
Requirement already satisfied: typing-extensions==3.7.4.2 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 49)) (3.7.4.2)
Requirement already satisfied: tzlocal==2.0.0 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 50)) (2.0.0)
Requirement already satisfied: urllib3==1.25.8 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 51)) (1.25.8)
Requirement already satisfied: Werkzeug==1.0.1 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 52)) (1.0.1)
Requirement already satisfied: wordcloud==1.8.0 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 53)) (1.8.0)
Requirement already satisfied: wrapt==1.11.2 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 54)) (1.11.2)
Requirement already satisfied: wsproto==0.15.0 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 55)) (0.15.0)
Requirement already satisfied: setuptools>=0.7 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from APScheduler==3.6.3->-r requirements.txt (line 4)) (41.2.0)

C:\software\Mirai\plugins\FG-mirai>python bot.py
  File "bot.py", line 2
SyntaxError: Non-UTF-8 code starting with '\xd6' in file bot.py on line 3, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
mgsky1 commented 4 years ago

应该不是ujson的问题,因为Python已经自动切换为了JSON模块进行解析。我怀疑跟你文件的编码有关,需要保证你所修改过的所有文件编码为UTF-8不带BOM。可以使用Microsoft Visual Studio Code编辑器查看。

byx2020 commented 4 years ago

应该不是ujson的问题,因为Python已经自动切换到JSON模块进行解析。我怀疑跟你文件的编码有关,需要保证你所修改过的所有文件编码为UTF-8不带BOM。可以使用Microsoft Visual Studio Code编辑器查看。

好的,我已经将FG-mirai文件夹下所有能够以文本形式打开的文件都全部检查完成了一遍,发现bot.py和config.json文件确实在之前的操作中被我不小心保存成了GB2312编码,我很快将它们以UTF8无签名编码进行了报错,并确认了其他文件都是UTF8无签名编码,再次使用python bot.py命令之后,上面File "bot.py", line 2的问题解决了,但是ujson module not found, using json的问题依然存在,这还可能是什么原因吗 image

C:\software\Mirai\plugins\CQHTTPMirai\FG-mirai>python bot.py
ujson module not found, using json
Traceback (most recent call last):
  File "bot.py", line 10, in <module>
    import config
  File "C:\software\Mirai\plugins\CQHTTPMirai\FG-mirai\config.py", line 11, in <module>
    configuration = JsonUtils.json2Dict(os.path.join(os.getcwd(),'cn','acmsmu','FG','data','config.json'))
  File "C:\software\Mirai\plugins\CQHTTPMirai\FG-mirai\Utils\JsonUtils.py", line 15, in json2Dict
    jsonDict = json.loads(f.read())
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\json\__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\json\decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Invalid control character at: line 29 column 42 (char 629)

C:\software\Mirai\plugins\CQHTTPMirai\FG-mirai>pip list
Package           Version
----------------- ----------
aiocache          0.11.1
aiocqhttp         1.2.5
aiofiles          0.4.0
APScheduler       3.6.3
astroid           2.3.3
beautifulsoup4    4.8.2
blinker           1.4
brainyquote       0.2
certifi           2019.11.28
chardet           3.0.4
click             7.1.1
colorama          0.4.3
cycler            0.10.0
decorator         4.4.2
h11               0.9.0
h2                3.2.0
hpack             3.0.0
hstspreload       2020.3.31
httpcore          0.10.2
httpx             0.12.1
Hypercorn         0.9.4
hyperframe        5.2.0
idna              2.9
isort             4.3.21
itsdangerous      1.1.0
jieba             0.42.1
Jinja2            2.11.1
kiwisolver        1.2.0
lazy-object-proxy 1.4.3
MarkupSafe        1.1.1
matplotlib        3.2.1
mccabe            0.6.1
msgpack           1.0.0
networkx          2.4
nonebot           1.5.0
numpy             1.18.2
Pillow            7.1.1
pip               20.2.2
priority          1.3.0
pylint            2.4.4
pyparsing         2.4.6
python-dateutil   2.8.1
pytz              2019.3
Quart             0.11.5
requests          2.23.0
rfc3986           1.3.2
setuptools        41.2.0
six               1.14.0
sniffio           1.1.0
soupsieve         2.0
textrank4zh       0.3
toml              0.10.0
typing-extensions 3.7.4.2
tzlocal           2.0.0
urllib3           1.25.8
Werkzeug          1.0.1
wordcloud         1.8.0
wrapt             1.11.2
wsproto           0.15.0
mgsky1 commented 4 years ago

先检查一下配置文件config.json格式是不是正确,编辑器有没有提示格式错误。

如果都没错的话,可以尝试一下下面这种方法:

找到/Utils/JsonUtils.py文件,原始代码是这样的:

'''
@Desc: JSON工具类
@Author: Martin Huang
@Date: 2020-04-01 21:23:38
@Modify Notes: 
    2020/04/01 => 增加从指定路径读取JSON配置文件,并返回字典
    2020/04/01 => 增加将JSON字符串转换成字典返回
'''
import json

class JsonUtils:
    #从指定路径path读取配置文件,并返回字典
    def json2Dict(path):
        with open(path,'r',encoding='utf-8') as f:
            jsonDict = json.loads(f.read())
        return jsonDict

    # 将JSON字符串转换为字典
    def jsonStr2Dict(jsonString):
        jsonDict = json.loads(jsonString)
        return jsonDict

修改成

'''
@Desc: JSON工具类
@Author: Martin Huang
@Date: 2020-04-01 21:23:38
@Modify Notes: 
    2020/04/01 => 增加从指定路径读取JSON配置文件,并返回字典
    2020/04/01 => 增加将JSON字符串转换成字典返回
'''
import json

class JsonUtils:
    #从指定路径path读取配置文件,并返回字典
    def json2Dict(path):
        with open(path,'r',encoding='utf-8') as f:
            jsonDict = json.loads(f.read(),strict=False)
        return jsonDict

    # 将JSON字符串转换为字典
    def jsonStr2Dict(jsonString):
        jsonDict = json.loads(jsonString,strict=False)
        return jsonDict

看看是否能正常运行

byx2020 commented 4 years ago

先检查一下配置文件config.json格式是不是正确,编辑器有没有提示格式错误。

如果都没错的话,可以尝试一下下面这种方法:

找到/Utils/JsonUtils.py文件,原始代码是这样的:

'''
@Desc: JSON工具类
@Author: Martin Huang
@Date: 2020-04-01 21:23:38
@Modify Notes: 
    2020/04/01 => 增加从指定路径读取JSON配置文件,并返回字典
    2020/04/01 => 增加将JSON字符串转换成字典返回
'''
import json

class JsonUtils:
    #从指定路径path读取配置文件,并返回字典
    def json2Dict(path):
        with open(path,'r',encoding='utf-8') as f:
            jsonDict = json.loads(f.read())
        return jsonDict

    # 将JSON字符串转换为字典
    def jsonStr2Dict(jsonString):
        jsonDict = json.loads(jsonString)
        return jsonDict

修改成

'''
@Desc: JSON工具类
@Author: Martin Huang
@Date: 2020-04-01 21:23:38
@Modify Notes: 
    2020/04/01 => 增加从指定路径读取JSON配置文件,并返回字典
    2020/04/01 => 增加将JSON字符串转换成字典返回
'''
import json

class JsonUtils:
    #从指定路径path读取配置文件,并返回字典
    def json2Dict(path):
        with open(path,'r',encoding='utf-8') as f:
            jsonDict = json.loads(f.read(),strict=False)
        return jsonDict

    # 将JSON字符串转换为字典
    def jsonStr2Dict(jsonString):
        jsonDict = json.loads(jsonString,strict=False)
        return jsonDict

看看是否能正常运行

我在本地电脑上用vs code检查了的config.json的格式,确实发现了一些语法上的错误,这大概是我之前在改json文件时脑子进了水,当然也可能与云服务器上没装vs code有关(借口),总之非常感谢大佬能抽时间指点迷津,另外,我在修正了config.json的格式并找到/Utils/JsonUtils.py文件进行修改后,使用python bot.py指令仍有ujson module not found, using json的提示,不过后面有了新的变化,我不太确定这意味着什么,是否仍有错误存在?

C:\software\Mirai\plugins\CQHTTPMirai\FG-mirai>python bot.py
ujson module not found, using json
{'windowSize': 5, 'keyWordLen': 3, 'keyWordNum': 50, 'fontPath': 'C:/Windows/Fonts/msyh.ttc', 'nonebotHost': '127.0.0.1', 'nonebotPort': 8080, 'cqhttpHost': '127.0.0.1', 'cqhttpPort': 5700, 'groupInfo': [{'timer': 'timer1', 'beginHour': 23, 'beginMinutes': 0, 'groupId': ''}], 'wcImg': [{'desc': '刘慈欣', 'fileNameO': 'lcx.jpg', 'fileNameU': 'lcx.png'}], 'template': [{'groupId': '691283312', 'content': [{'0': '@所有人', '1': '大家好,我是FG,第五代电子计算机', '2': '这是FG在向群里所有成员广播:', '3': '欢迎每晚XX点锁定XXX群,收看由每日聊天信息自动生成的每日热词', 'time': '收入时间为:{string}到{string},今日的热点关键词为', 'content': '{string}', 'wcImg': '今日词云:{img}', 'wcImgDesc': '今日背景图为 {string}', 'oriImg': '原图:{img}', '9': '热词生成的宗旨是为您节约时间,让您无需时时在线就能了解动态', '10': '如果您对此感兴趣,欢迎 每晚XX点进入XXX群~再见!'}, {'0': '@所有人', '1': '大家好,我是FG,第五代电子计算机', '2': '这是FG在向群里所有成员广播:', '3': '欢迎每晚XX点锁定XXX群,收看由每日聊天信息自动生成的每日热词', '4': '今日群里不够热闹,因此今日无热词', '5': '热 词生成的宗旨是为您节约时间,让您无需时时在线就能了解动态', '6': '如果您对此感兴趣,欢迎每晚XX点进入XXX群~再见!'}]}]}
定时器timer1定时任务添加成功!
初始化完成
[2020-09-01 20:05:40,706 nonebot] INFO: Succeeded to import "cn.acmsmu.FG"
[2020-09-01 20:05:40,706 nonebot] INFO: Running on 127.0.0.1:8080
Running on http://127.0.0.1:8080 (CTRL + C to quit)
[2020-09-01 20:05:40,721 nonebot] INFO: Scheduler started
[2020-09-01 20:05:40,737] Running on 127.0.0.1:8080 over http (CTRL + C to quit)

image

mgsky1 commented 4 years ago

先检查一下配置文件config.json格式是不是正确,编辑器有没有提示格式错误。 如果都没错的话,可以尝试一下下面这种方法: 找到/Utils/JsonUtils.py文件,原始代码是这样的:

'''
@Desc: JSON工具类
@Author: Martin Huang
@Date: 2020-04-01 21:23:38
@Modify Notes: 
    2020/04/01 => 增加从指定路径读取JSON配置文件,并返回字典
    2020/04/01 => 增加将JSON字符串转换成字典返回
'''
import json

class JsonUtils:
    #从指定路径path读取配置文件,并返回字典
    def json2Dict(path):
        with open(path,'r',encoding='utf-8') as f:
            jsonDict = json.loads(f.read())
        return jsonDict

    # 将JSON字符串转换为字典
    def jsonStr2Dict(jsonString):
        jsonDict = json.loads(jsonString)
        return jsonDict

修改成

'''
@Desc: JSON工具类
@Author: Martin Huang
@Date: 2020-04-01 21:23:38
@Modify Notes: 
    2020/04/01 => 增加从指定路径读取JSON配置文件,并返回字典
    2020/04/01 => 增加将JSON字符串转换成字典返回
'''
import json

class JsonUtils:
    #从指定路径path读取配置文件,并返回字典
    def json2Dict(path):
        with open(path,'r',encoding='utf-8') as f:
            jsonDict = json.loads(f.read(),strict=False)
        return jsonDict

    # 将JSON字符串转换为字典
    def jsonStr2Dict(jsonString):
        jsonDict = json.loads(jsonString,strict=False)
        return jsonDict

看看是否能正常运行

我在本地电脑上用vs code检查了的config.json的格式,确实发现了一些语法上的错误,这大概是我之前在改json文件时脑子进了水,当然也可能与云服务器上没装vs code有关(借口),总之非常感谢大佬能抽时间指点迷津,另外,我在修正了config.json的格式并找到/Utils/JsonUtils.py文件进行修改后,使用python bot.py指令仍有ujson module not found, using json的提示,不过后面有了新的变化,我不太确定这意味着什么,是否仍有错误存在?

C:\software\Mirai\plugins\CQHTTPMirai\FG-mirai>python bot.py
ujson module not found, using json
{'windowSize': 5, 'keyWordLen': 3, 'keyWordNum': 50, 'fontPath': 'C:/Windows/Fonts/msyh.ttc', 'nonebotHost': '127.0.0.1', 'nonebotPort': 8080, 'cqhttpHost': '127.0.0.1', 'cqhttpPort': 5700, 'groupInfo': [{'timer': 'timer1', 'beginHour': 23, 'beginMinutes': 0, 'groupId': ''}], 'wcImg': [{'desc': '刘慈欣', 'fileNameO': 'lcx.jpg', 'fileNameU': 'lcx.png'}], 'template': [{'groupId': '691283312', 'content': [{'0': '@所有人', '1': '大家好,我是FG,第五代电子计算机', '2': '这是FG在向群里所有成员广播:', '3': '欢迎每晚XX点锁定XXX群,收看由每日聊天信息自动生成的每日热词', 'time': '收入时间为:{string}到{string},今日的热点关键词为', 'content': '{string}', 'wcImg': '今日词云:{img}', 'wcImgDesc': '今日背景图为 {string}', 'oriImg': '原图:{img}', '9': '热词生成的宗旨是为您节约时间,让您无需时时在线就能了解动态', '10': '如果您对此感兴趣,欢迎 每晚XX点进入XXX群~再见!'}, {'0': '@所有人', '1': '大家好,我是FG,第五代电子计算机', '2': '这是FG在向群里所有成员广播:', '3': '欢迎每晚XX点锁定XXX群,收看由每日聊天信息自动生成的每日热词', '4': '今日群里不够热闹,因此今日无热词', '5': '热 词生成的宗旨是为您节约时间,让您无需时时在线就能了解动态', '6': '如果您对此感兴趣,欢迎每晚XX点进入XXX群~再见!'}]}]}
定时器timer1定时任务添加成功!
初始化完成
[2020-09-01 20:05:40,706 nonebot] INFO: Succeeded to import "cn.acmsmu.FG"
[2020-09-01 20:05:40,706 nonebot] INFO: Running on 127.0.0.1:8080
Running on http://127.0.0.1:8080 (CTRL + C to quit)
[2020-09-01 20:05:40,721 nonebot] INFO: Scheduler started
[2020-09-01 20:05:40,737] Running on 127.0.0.1:8080 over http (CTRL + C to quit)

image

ujson module not found, using json 这个不用管。

这说明机器人已经成功运行了,剩下要做的就是Mirai和cqhttp-mirai配置了,如果你已经配置过了,那么就可以使用了。

有疑问还可以继续留言

byx2020 commented 4 years ago

先检查一下配置文件config.json格式是不是正确,编辑器有没有提示格式错误。 如果都没错的话,可以尝试一下下面这种方法: 找到/Utils/JsonUtils.py文件,原始代码是这样的:

'''
@Desc: JSON工具类
@Author: Martin Huang
@Date: 2020-04-01 21:23:38
@Modify Notes: 
    2020/04/01 => 增加从指定路径读取JSON配置文件,并返回字典
    2020/04/01 => 增加将JSON字符串转换成字典返回
'''
import json

class JsonUtils:
    #从指定路径path读取配置文件,并返回字典
    def json2Dict(path):
        with open(path,'r',encoding='utf-8') as f:
            jsonDict = json.loads(f.read())
        return jsonDict

    # 将JSON字符串转换为字典
    def jsonStr2Dict(jsonString):
        jsonDict = json.loads(jsonString)
        return jsonDict

修改成

'''
@Desc: JSON工具类
@Author: Martin Huang
@Date: 2020-04-01 21:23:38
@Modify Notes: 
    2020/04/01 => 增加从指定路径读取JSON配置文件,并返回字典
    2020/04/01 => 增加将JSON字符串转换成字典返回
'''
import json

class JsonUtils:
    #从指定路径path读取配置文件,并返回字典
    def json2Dict(path):
        with open(path,'r',encoding='utf-8') as f:
            jsonDict = json.loads(f.read(),strict=False)
        return jsonDict

    # 将JSON字符串转换为字典
    def jsonStr2Dict(jsonString):
        jsonDict = json.loads(jsonString,strict=False)
        return jsonDict

看看是否能正常运行

我在本地电脑上用vs code检查了的config.json的格式,确实发现了一些语法上的错误,这大概是我之前在改json文件时脑子进了水,当然也可能与云服务器上没装vs code有关(借口),总之非常感谢大佬能抽时间指点迷津,另外,我在修正了config.json的格式并找到/Utils/JsonUtils.py文件进行修改后,使用python bot.py指令仍有ujson module not found, using json的提示,不过后面有了新的变化,我不太确定这意味着什么,是否仍有错误存在?

C:\software\Mirai\plugins\CQHTTPMirai\FG-mirai>python bot.py
ujson module not found, using json
{'windowSize': 5, 'keyWordLen': 3, 'keyWordNum': 50, 'fontPath': 'C:/Windows/Fonts/msyh.ttc', 'nonebotHost': '127.0.0.1', 'nonebotPort': 8080, 'cqhttpHost': '127.0.0.1', 'cqhttpPort': 5700, 'groupInfo': [{'timer': 'timer1', 'beginHour': 23, 'beginMinutes': 0, 'groupId': ''}], 'wcImg': [{'desc': '刘慈欣', 'fileNameO': 'lcx.jpg', 'fileNameU': 'lcx.png'}], 'template': [{'groupId': '691283312', 'content': [{'0': '@所有人', '1': '大家好,我是FG,第五代电子计算机', '2': '这是FG在向群里所有成员广播:', '3': '欢迎每晚XX点锁定XXX群,收看由每日聊天信息自动生成的每日热词', 'time': '收入时间为:{string}到{string},今日的热点关键词为', 'content': '{string}', 'wcImg': '今日词云:{img}', 'wcImgDesc': '今日背景图为 {string}', 'oriImg': '原图:{img}', '9': '热词生成的宗旨是为您节约时间,让您无需时时在线就能了解动态', '10': '如果您对此感兴趣,欢迎 每晚XX点进入XXX群~再见!'}, {'0': '@所有人', '1': '大家好,我是FG,第五代电子计算机', '2': '这是FG在向群里所有成员广播:', '3': '欢迎每晚XX点锁定XXX群,收看由每日聊天信息自动生成的每日热词', '4': '今日群里不够热闹,因此今日无热词', '5': '热 词生成的宗旨是为您节约时间,让您无需时时在线就能了解动态', '6': '如果您对此感兴趣,欢迎每晚XX点进入XXX群~再见!'}]}]}
定时器timer1定时任务添加成功!
初始化完成
[2020-09-01 20:05:40,706 nonebot] INFO: Succeeded to import "cn.acmsmu.FG"
[2020-09-01 20:05:40,706 nonebot] INFO: Running on 127.0.0.1:8080
Running on http://127.0.0.1:8080 (CTRL + C to quit)
[2020-09-01 20:05:40,721 nonebot] INFO: Scheduler started
[2020-09-01 20:05:40,737] Running on 127.0.0.1:8080 over http (CTRL + C to quit)

image

ujson module not found, using json 这个不用管。

这说明机器人已经成功运行了,剩下要做的就是Mirai和cqhttp-mirai配置了,如果你已经配置过了,那么就可以使用了。

有疑问还可以继续留言

好的,不过我之前一直使用的是mirai-native,并没有用过cqhttp-mirai,可能还需要去看cqhttp-mirai的说明文档再修改调试一下,总之辛苦大佬指点了

byx2020 commented 4 years ago

应该不是ujson的问题,因为Python已经自动切换到JSON模块进行解析。我怀疑跟你文件的编码有关,需要保证你所修改过的所有文件编码为UTF-8不带BOM。可以使用Microsoft Visual Studio Code编辑器查看。

我按照nonebot和CQHTTP Mirai的教程设置完成后,确实在NoneBot 所在的控制台输出了日志(如下图所示),但是向机器人发送/echo 你好,世界却并无回应(nonebot的说明文档似乎都是针对CQHTTP的),不过我这次想问的是,我应该如何确认FG-Mirai是否处于正常工作的状态或者是处于出错的状态?我怀疑我装的FG-Mirai可能处于宕机状态,因为没有日志表明FG-Mirai正在工作,这让我不太放心,另外,附上我的plugins/CQHTTPMirai/setting.yml配置文件的设置,是不是这里面有配置错误的地方,大佬有时间的话帮忙看一下就好,麻烦了。 image

debug: true
proxy: "http=http://127.0.0.1:8888"
'2709800974':
  cacheImage: false
  cacheRecord: false
  heartbeat:
    enable: false
    interval: 15000
  http:
    enable: true
    host: 127.0.0.1
    port: 5700
    accessToken: ""
    postUrl: ""
    postMessageFormat: string
    secret: ""
  ws_reverse:
    - enable: true
      postMessageFormat: string
      reverseHost: 127.0.0.1
      reversePort: 8080
      accessToken: ""
      reversePath: /ws
      reverseApiPath: /api
      reverseEventPath: /event
      useUniversal: true
      useTLS: false
      reconnectInterval: 3000
  ws:
    enable: true
    postMessageFormat: string
    accessToken: ""
    wsHost: "127.0.0.1"
    wsPort: 8080

果然有错误,更新一下

Run time of job "handleTimer (trigger: cron[hour='23', minute='0'], next run at: 2020-09-03 23:00:00 CST)" was missed by 0:00:01.567923
[2020-09-02 23:00:05,256] INFO in __init__: received event: message.group.normal
byx2020 commented 4 years ago

应该不是ujson的问题,因为Python已经自动切换到JSON模块进行解析。我怀疑跟你文件的编码有关,需要保证你所修改过的所有文件编码为UTF-8不带BOM。可以使用Microsoft Visual Studio Code编辑器查看。

我按照nonebot和CQHTTP Mirai的教程设置完成后,确实在NoneBot 所在的控制台输出了日志(如下图所示),但是向机器人发送/echo 你好,世界却并无回应(nonebot的说明文档似乎都是针对CQHTTP的),不过我这次想问的是,我应该如何确认FG-Mirai是否处于正常工作的状态或者是处于出错的状态?我怀疑我装的FG-Mirai可能处于宕机状态,因为没有日志表明FG-Mirai正在工作,这让我不太放心,另外,附上我的plugins/CQHTTPMirai/setting.yml配置文件的设置,是不是这里面有配置错误的地方,大佬有时间的话帮忙看一下就好,麻烦了。 image

debug: false
proxy: "http=http://127.0.0.1:8888"
'2709800974':
cacheImage: false
cacheRecord: false
heartbeat:
enable: false
interval: 15000
http:
enable: true
host: 127.0.0.1
port: 5700
accessToken: ""
postUrl: ""
postMessageFormat: string
secret: ""
ws_reverse:
- enable: true
postMessageFormat: string
reverseHost: 127.0.0.1
reversePort: 8080
accessToken: ""
reversePath: /ws
reverseApiPath: /api
reverseEventPath: /event
useUniversal: true
useTLS: false
reconnectInterval: 3000
- enable: true
postMessageFormat: string
reverseHost: 127.0.0.1
reversePort: 8080
reversePath: /ws
useUniversal: false
reconnectInterval: 3000
ws:
enable: true
postMessageFormat: string
accessToken: ""
wsHost: "127.0.0.1"
wsPort: 8080

果然有错误,更新一下

Run time of job "handleTimer (trigger: cron[hour='23', minute='0'], next run at: 2020-09-03 23:00:00 CST)" was missed by 0:00:01.567923
[2020-09-02 23:00:05,256] INFO in __init__: received event: message.group.normal
byx2020 commented 4 years ago

应该不是ujson的问题,因为Python已经自动切换到JSON模块进行解析。我怀疑跟你文件的编码有关,需要保证你所修改过的所有文件编码为UTF-8不带BOM。可以使用Microsoft Visual Studio Code编辑器查看。

我按照nonebot和CQHTTP Mirai的教程设置完成后,确实在NoneBot 所在的控制台输出了日志(如下图所示),但是向机器人发送/echo 你好,世界却并无回应(nonebot的说明文档似乎都是针对CQHTTP的),不过我这次想问的是,我应该如何确认FG-Mirai是否处于正常工作的状态或者是处于出错的状态?我怀疑我装的FG-Mirai可能处于宕机状态,因为没有日志表明FG-Mirai正在工作,这让我不太放心,另外,附上我的plugins/CQHTTPMirai/setting.yml配置文件的设置,是不是这里面有配置错误的地方,大佬有时间的话帮忙看一下就好,麻烦了。 image

debug: false
proxy: "http=http://127.0.0.1:8888"
'2709800974':
cacheImage: false
cacheRecord: false
heartbeat:
enable: false
interval: 15000
http:
enable: true
host: 127.0.0.1
port: 5700
accessToken: ""
postUrl: ""
postMessageFormat: string
secret: ""
ws_reverse:
- enable: true
postMessageFormat: string
reverseHost: 127.0.0.1
reversePort: 8080
accessToken: ""
reversePath: /ws
reverseApiPath: /api
reverseEventPath: /event
useUniversal: true
useTLS: false
reconnectInterval: 3000
- enable: true
postMessageFormat: string
reverseHost: 127.0.0.1
reversePort: 8080
reversePath: /ws
useUniversal: false
reconnectInterval: 3000
ws:
enable: true
postMessageFormat: string
accessToken: ""
wsHost: "127.0.0.1"
wsPort: 8080

果然有错误,更新一下

Run time of job "handleTimer (trigger: cron[hour='23', minute='0'], next run at: 2020-09-03 23:00:00 CST)" was missed by 0:00:01.567923
[2020-09-02 23:00:05,256] INFO in __init__: received event: message.group.normal
byx2020 commented 4 years ago
Run time of job "handleTimer (trigger: cron[hour='23', minute='0'], next run at: 2020-09-05 23:00:00 CST)" was missed by 0:00:01.629698
[2020-09-04 23:00:10,812] INFO in __init__: received event: message.group.normal
mgsky1 commented 4 years ago

那个echo语法是Nonebot最原始的用法,我已经把它给去掉了,然后要确保FG是否正在工作的话,加载的时候,应该会在控制台输出XXX加载成功,还有你的配置文件之类的日志。如果有,说明它已经在运行了。

看你的截图,说明它已经在运行了。这个分支只能够等设定时间到了,然后看看机器人会不会有反应。另外一个定制版的分支是有一些写死的Q&A的,可以测试机器人是否正常

byx2020 commented 4 years ago

那个echo语法是Nonebot最原始的用法,我已经把它给去掉了,然后要确保FG是否正在工作的话,加载的时候,应该会在控制台输出XXX加载成功,还有你的配置文件之类的日志。如果有,说明它已经在运行了。

看你的截图,说明它已经在运行了。这个分支只能够等设定时间到了,然后看看机器人会不会有反应。另外一个定制版的分支是有一些写死的Q&A的,可以测试机器人是否正常

好的,了解了