Comments (16)
首先 酷Q air版本没这个问题。升级为pro时候遇到的。
我先启动的自己写的机器人脚本,再启动酷Q,我在脚本的代码里面做了一次http请求,请求结束做了一次数据解析。就报上面的错了。
但是如果我先启动的酷Q,再启动自己写的脚本,就不会出现这个错误
from nonebot.
这个应该是使用的基础 web 服务器 Hypercorn 的问题,我也遇到过,但不涉及 NoneBot 的代码出现这个报错应该不影响实际使用吧
from nonebot.
这个错误发生之后,脚本就再也收不到数据了,两者之间的交互就断了。目前就是靠上面说的启动顺序来规避这个错误发生QAQ
from nonebot.
每次都能复现?
from nonebot.
差不多,频率很高。需要的话 我也给你我的代码。不过感觉应该不是代码的问题。
from nonebot.
from none import on_command, CommandSession
import json
from bs4 import BeautifulSoup
import none
from luoqi.plugins import my_http
import re
config = []
headers = {'User-Agent': 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6',"contentType":"text/html; charset=utf-8"}
@on_command('shifang', aliases=( '释放卷', '释放','shifan','shifang'), only_to_me=False)
async def chashifang(session: CommandSession):
global config
if session.get('param', prompt='查询失败?') == False:
return
juan = session.get('juan', prompt='查询失败?')
if config == [] or juan == "更新" or juan == "update":
await session.send("释放卷内容更新中,请稍后查询")
result = await update_shifang_config()
if not result:
await session.send("释放卷内容更新失败,请重新更新")
return
if juan == "更新" or juan == "update":
await session.send("释放卷内容更新成功")
return
userid = None
if "group_id" in session.ctx:
userid = session.ctx['user_id']
juan_info = await get_info_of_juan(juan,userid)
# print(session.ctx)
await session.send(juan_info)
@chashifang.args_parser
async def _(session: CommandSession):
session.args['param'] = True
stripped_arg = session.current_arg_text.strip()
if not stripped_arg:
session.args['param'] = False
if session.current_key:
session.args[session.current_key] = stripped_arg
elif stripped_arg:
session.args['juan'] = stripped_arg
async def update_shifang_config() -> str:
global config
print("aaaaaaaaaaa")
result = my_http.api_query("https://github.com/zafeishiya/mabinogy/blob/master/shifang.txt", headers)
if not result:
return ""
print("000000000000")
soup = BeautifulSoup(result, 'lxml')
print("11111111")
info = soup.select('table[class="highlight tab-size js-file-line-container"]')[0].get_text().strip().replace(
""", '"').replace(">", " ").replace(r"\n", "").replace("\n", "").replace("\\", "").replace("\t", "")
print("22222222")
info = re.sub(r", *\]", "]", info)
print("33333333")
#print(info)
config = json.loads(info)
return "123"
async def get_info_of_juan(name: str,userid:str) -> str:
result = ""
contain_list = []
equal_list = []
for info in config:
if info[0] == name:
equal_list.append(info)
elif name in info[0] or info[0] in name:
contain_list.append(info)
if len(equal_list) == 0:
result += "找不到释放卷:" + name + '\n'
else:
for info in equal_list:
result += info[0]+ "\n"
result += "" +info[1]+ "\n"
result += "位置:" + info[2]+ "\n"
result += "属性效果:" + info[3]+ "\n"
result += "来源:" + info[4] + "\n"
result += "----------------\n"
if len(contain_list) > 0:
result += "你可能要查找的是: "
for info in contain_list:
result += info[0] + "? "
if userid:
result = f'[CQ:at,qq={userid}]\n' + result
result += "\n数据来源:迪尔纳诺。"
return result
我写了三个脚本,上面这个是报错最频繁的脚本。
第一个脚本没有做http 请求,基本不会报错。
第二个脚本请求的数据不是很大,拉取了我在github上面的提交的文件内容。报错概率比较低
第三个就是上面的脚本,拉取的数据量比较大,url在代码里面有。基本90%会报错。
先开脚本,再启动或重启酷Q才会报错。您那边可以执行的话,启动后输入 释放 更新。就可以看到报错了
报错日志的话一般在print 00000之后 print 11111中间输出的。 22222 3333这些日志最终都打印了
from nonebot.
emmm,你的代码,用 ``` 包裹一下吧,已经完全看不出来了
from nonebot.
加了。。原来还可以用三个`的么。尴尬。
from nonebot.
result = my_http.api_query("https://github.com/zafeishiya/mabinogy/blob/master/shifang.txt", headers)
你这个 HTTP 请求的地方需要使用 aiohttp 之类的异步 IO 的库
from nonebot.
async def fetch(session, url):
async with session.get(url) as response:
return await response.text()
async def update_shifang_config() -> str:
global config
print("aaaaaaaaaaa")
#result = my_http.api_query("https://github.com/zafeishiya/mabinogy/blob/master/shifang.txt", headers)
result = ""
async with aiohttp.ClientSession() as session:
result = await fetch(session, "https://github.com/zafeishiya/mabinogy/blob/master/shifang.txt")
if not result:
return ""
print("000000000000")
soup = BeautifulSoup(result, 'lxml')
print("11111111")
info = soup.select('table[class="highlight tab-size js-file-line-container"]')[0].get_text().strip().replace(
""", '"').replace(">", " ").replace(r"\n", "").replace("\n", "").replace("\\", "").replace("\t", "")
print("22222222")
info = re.sub(r", *\]", "]", info)
print("33333333")
print(info)
config = json.loads(info)
return "123"
我把代码换成了aiohttp,还是一样的问题.
from nonebot.
迪尔纳诺!???题主洛奇玩家??
from nonebot.
@yorushika 甚至开始版聊了(
from nonebot.
from nonebot.
from nonebot.
是先开的脚本,再启动的酷Q么 0.0
重现不出来就先算了QAQ我先用启动顺序规避了吧。
from nonebot.
我又试了先启动脚本,也没问题(
from nonebot.
Related Issues (20)
- 请问如何在只是User is calling me的情况下保持会话? HOT 2
- scheduler与message_preprocessor不在同一个eventloop导致两者之间很难进行同步 HOT 6
- nonebot+cqhttp反向websocket 时出现错误: websocket: bad handshake HOT 8
- [提问]如何关闭heartbeat的logging HOT 6
- aget 无法发送prompt HOT 3
- 1.8.3移除`CommandSession.args`导致类 Shell 参数解析Command出错 HOT 2
- 以 node-onebot 为后端无法正确设置 `ctx['to_me']` HOT 5
- 加載“失敗”的插件注冊的命令仍然可用 HOT 1
- 考慮移除 sched HOT 1
- NLPSession无法处理被两个qq表情夹着的关键词 HOT 11
- 运行`nb run`命令后直接抛出`cannot import name 'WebSocketSetup' from 'nonebot.drivers' ` HOT 1
- say 和 echo失踪 HOT 3
- NLPSession在较长的句子中不能识别到关键词 HOT 2
- 1
- 关于Pyinstaller打包后的exe为什么会报错的解决方案【建议调整一部分代码】
- 启动时遇到ImportError HOT 2
- m1 运行报错cannot import name 'escape' from 'jinja2' HOT 9
- ImportError: cannot import name 'overrides' from 'nonebot.typing' HOT 1
- 无法正确识别“回复”类型消息中的指令 HOT 2
- 按组一同注册命令的关键词 内容 权限 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nonebot.