SonderXiaoming / pcrjjc_huannai

GNU Affero General Public License v3.0
14 stars 6 forks source link

无法正确触发重登 #27

Closed HMScygnet closed 1 year ago

HMScygnet commented 1 year ago

查询用号掉线以后不尝试重登,无法使用竞技场功能,只能整个重启

HMScygnet commented 1 year ago

已确认不是风控问题,我设了一个指令手动清空循环才能正确发送验证码链接

try:
    loog = asyncio.get_running_loop()
    loop.close()
except:
    pass
for i in acinfo:
    bclient = bsdkclient(i, captchaVerifier, errlogger)
    client = pcrclient(bclient)
    loop = asyncio.get_event_loop()
    loop.create_task(query(client))
await bot.send(ev,'登陆成功')
HMScygnet commented 1 year ago

看了下源项目,可能是因为这个?https://github.com/cc004/pcrjjc2/commit/222cd5a0780f6f46a1790908d4c654ca15496781

SonderXiaoming commented 1 year ago

好像有这回事,但是我没遇到过,建议先自行修改尝试

HMScygnet commented 1 year ago

看了下源项目,可能是因为这个?cc004/pcrjjc2@222cd5a

试了一下这个并没有用,目前只能靠手动重连先顶着

SonderXiaoming commented 1 year ago

是不是过码的问题

HMScygnet commented 1 year ago

是不是过码的问题

不是,我是手动过码,清空循环重登才发链接

HMScygnet commented 1 year ago

经测试是由于B站服务端不响应导致的,request的timeou仅针对本地网络异常,可以在pcrclient.pyclass pcrclient中使用asyncio.wait_for来检测超时

...
async def request_with_timeout(self,session, url, data, headers, timeout):
    try:
        response = await session.post(url, data=data, headers=headers)
        return await response.content.read()
    except asyncio.TimeoutError:
        print("请求超时")
        return None

async def callapi(self, apiurl: str, request: dict, crypted: bool = True, noerr: bool = False):
    key = pcrclient.createkey()

    try:    
        if self.viewer_id is not None:
            request['viewer_id'] = b64encode(pcrclient.encrypt(str(self.viewer_id), key)) if crypted else str(self.viewer_id)
        url = apiroot + apiurl
        data = pcrclient.pack(request, key) if crypted else str(request).encode('utf8')

        async with aiohttp.ClientSession() as session:
            response = await asyncio.wait_for(
                self.request_with_timeout(session, url, data, self.headers, 10),
                timeout=10
            )
            if response is not None:
                pass
            else:
                self.shouldLogin = True
                raise
...
SonderXiaoming commented 1 year ago

你调大timeout是不是效果一样,aiohttp是你自己之前改的?

HMScygnet commented 1 year ago

你调大timeout是不是效果一样,aiohttp是你自己之前改的?

这个问题是由于服务端不响应导致的,与timeout数值无关,服务端不响应就会一直等下去,aiohttp是我自己改的,用hoshino的aiorequests应该也行

SonderXiaoming commented 1 year ago

你先改回aiorequests试试

HMScygnet commented 1 year ago

aiorequests也行,小改一下

    async def request_with_timeout(self,url, data, headers, timeout):
        try:
            response = await post(url, data=data, headers=headers,timeout=timeout)
            return await response.content
        except asyncio.TimeoutError:
            print("请求超时")
            return None

    async def callapi(self, apiurl: str, request: dict, crypted: bool = True, noerr: bool = False):
        key = pcrclient.createkey()

        try:    
            if self.viewer_id is not None:
                request['viewer_id'] = b64encode(pcrclient.encrypt(str(self.viewer_id), key)) if crypted else str(self.viewer_id)
            url = apiroot + apiurl
            data = pcrclient.pack(request, key) if crypted else str(request).encode('utf8')

            response = await asyncio.wait_for(
                self.request_with_timeout(url, data, self.headers, 10),
                timeout=10
            )
            if response is not None:
                pass
            else:
                self.shouldLogin = True
                raise