Giter VIP home page Giter VIP logo

Comments (16)

mabi-zafeishiya avatar mabi-zafeishiya commented on July 21, 2024

首先 酷Q air版本没这个问题。升级为pro时候遇到的。
我先启动的自己写的机器人脚本,再启动酷Q,我在脚本的代码里面做了一次http请求,请求结束做了一次数据解析。就报上面的错了。
但是如果我先启动的酷Q,再启动自己写的脚本,就不会出现这个错误

from nonebot.

stdrc avatar stdrc commented on July 21, 2024

这个应该是使用的基础 web 服务器 Hypercorn 的问题,我也遇到过,但不涉及 NoneBot 的代码出现这个报错应该不影响实际使用吧

from nonebot.

mabi-zafeishiya avatar mabi-zafeishiya commented on July 21, 2024

这个错误发生之后,脚本就再也收不到数据了,两者之间的交互就断了。目前就是靠上面说的启动顺序来规避这个错误发生QAQ

from nonebot.

stdrc avatar stdrc commented on July 21, 2024

每次都能复现?

from nonebot.

mabi-zafeishiya avatar mabi-zafeishiya commented on July 21, 2024

差不多,频率很高。需要的话 我也给你我的代码。不过感觉应该不是代码的问题。

from nonebot.

mabi-zafeishiya avatar mabi-zafeishiya commented on July 21, 2024
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("&gt", " ").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.

stdrc avatar stdrc commented on July 21, 2024

emmm,你的代码,用 ``` 包裹一下吧,已经完全看不出来了

from nonebot.

mabi-zafeishiya avatar mabi-zafeishiya commented on July 21, 2024

加了。。原来还可以用三个`的么。尴尬。

from nonebot.

stdrc avatar stdrc commented on July 21, 2024

result = my_http.api_query("https://github.com/zafeishiya/mabinogy/blob/master/shifang.txt", headers)

你这个 HTTP 请求的地方需要使用 aiohttp 之类的异步 IO 的库

from nonebot.

sijunjie avatar sijunjie commented on July 21, 2024
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("&gt", " ").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.

miranquil avatar miranquil commented on July 21, 2024

迪尔纳诺!???题主洛奇玩家??

from nonebot.

stdrc avatar stdrc commented on July 21, 2024

@yorushika 甚至开始版聊了(

from nonebot.

sijunjie avatar sijunjie commented on July 21, 2024

from nonebot.

stdrc avatar stdrc commented on July 21, 2024

你这个新的代码我测试没有问题
image
image

from nonebot.

sijunjie avatar sijunjie commented on July 21, 2024

是先开的脚本,再启动的酷Q么 0.0
重现不出来就先算了QAQ我先用启动顺序规避了吧。

from nonebot.

stdrc avatar stdrc commented on July 21, 2024

我又试了先启动脚本,也没问题(

from nonebot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.