A-kirami / nonebot-plugin-chatgpt

MIT License
319 stars 37 forks source link

[BUG]: __Secure-next-auth.session-token会在当前浏览页面失去焦点时自动更改 #68

Open black-zero358 opened 1 year ago

black-zero358 commented 1 year ago

报告清单

影响版本

0.7.0

问题描述

image 开启系统代理(日本节点,并没有使用CHATGPT_PROXIES)的情况下,只要当前页面失去焦点,_Secure-next-auth.session-token就会变化,对应到插件中就是无限获取 image 在关闭系统代理之后,网页也是一样的情况,只不过插件那边的情况有所不同 image image

最总导致的结果就是无法正常使用插件 image 但是昨天我测试的时候还是可以正常使用,只不过使用的是当时还未合并的分支https://github.com/A-kirami/nonebot-plugin-chatgpt/pull/52 不过应该跟这个关系不大。 不知道是不是跟账号本身有关系?

复现步骤

https://chat.openai.com/chat 上面的页面失去焦点,就会导致__Secure-next-auth.session-token变化

预期行为

No response

实际行为

No response

日志信息

No response

额外补充

No response

ShanShuWu commented 1 year ago

我也遇到了这种情况,下午token失效了就去网站重新拉token,结果怎么更换都不行,结果发现网站的token一直在变

lmst2 commented 1 year ago

我和我的朋友都遇到了这个问题

ShanShuWu commented 1 year ago

目前有什么好的方案吗

lmst2 commented 1 year ago

目前看到了就是他的页面有个函数,会在页面失去焦点的时候自动访问auth/session获取最新token,我的做法是维持页面最大化,然后直接复制最新token粘贴到配置文件里,再启动机器人,测试发现没问题之后立刻关闭网页,不让它有刷新的机会

lmst2 commented 1 year ago

我用的版本当时这个pr还没有migrate,因为有cf防火墙,原版用不了,所以直接checkout的他那个还没有migrate的版本,并没有你这个重复获取token的问题

lmst2 commented 1 year ago

gh pr checkout 52

sena-nana commented 1 year ago

token失效的错误是因为另外一个bug,在昨天另外一个pr修的,现在也已经合并

black-zero358 commented 1 year ago

token失效的错误是因为另外一个bug,在昨天另外一个pr修的,现在也已经合并 不知道是哪里出了问题,在不开启代理的情况下不再是token失效反而出现了另外的错误 我再试着找找哪里出了问题 image

image

image 12-14 21:10:37 [DEBUG] nonebot_plugin_chatgpt | 正在刷新session
12-14 21:10:38 [DEBUG] nonebot_plugin_chatgpt | 正在获取cf cookies 12-14 21:10:46 [DEBUG] nonebot_plugin_chatgpt | cf cookies获取成功 12-14 21:10:46 [DEBUG] nonebot_plugin_chatgpt | 正在刷新session
12-14 21:10:47 [ERROR] nonebot_plugin_chatgpt | 刷新会话失败: HTTP200 {} Traceback (most recent call last): File "D:\ENV\python_310\lib\runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None, File "D:\ENV\python_310\lib\runpy.py", line 86, in _run_code exec(code, run_globals) File "D:\ENV\python_310\Scripts\nb.exe__main.py", line 7, in sys.exit(main()) File "D:\ENV\python_310\lib\site-packages\click\core.py", line 1130, in call return self.main(args, kwargs) File "D:\ENV\python_310\lib\site-packages\click\core.py", line 1055, in main rv = self.invoke(ctx) File "D:\ENV\python_310\lib\site-packages\click\core.py", line 1657, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "D:\ENV\python_310\lib\site-packages\click\core.py", line 1404, in invoke return ctx.invoke(self.callback, ctx.params) File "D:\ENV\python_310\lib\site-packages\click\core.py", line 760, in invoke return __callback(args, kwargs) File "D:\ENV\python_310\lib\site-packages\nb_cli\commands\main.py", line 30, in run run_bot(file, app) File "D:\ENV\python_310\lib\site-packages\nb_cli\handlers\deploy.py", line 25, in run_bot nonebot.run(app=f"{module_name}:{app}") File "D:\ENV\python_310\lib\site-packages\nonebot__init__.py", line 273, in run get_driver().run(*args, *kwargs) File "D:\ENV\python_310\lib\site-packages\nonebot\drivers\fastapi.py", line 172, in run uvicorn.run( File "D:\ENV\python_310\lib\site-packages\uvicorn\main.py", line 569, in run server.run() File "D:\ENV\python_310\lib\site-packages\uvicorn\server.py", line 60, in run return asyncio.run(self.serve(sockets=sockets)) File "D:\ENV\python_310\lib\asyncio\runners.py", line 44, in run
return loop.run_until_complete(main) File "D:\ENV\python_310\lib\asyncio\base_events.py", line 636, in run_until_complete self.run_forever() File "D:\ENV\python_310\lib\asyncio\windows_events.py", line 321, in run_forever super().run_forever() File "D:\ENV\python_310\lib\asyncio\base_events.py", line 603, in run_forever self._run_once() File "D:\ENV\python_310\lib\asyncio\base_events.py", line 1906, in _run_once handle._run() File "D:\ENV\python_310\lib\asyncio\events.py", line 80, in _run
self._context.run(self._callback,
self._args) File "D:\ENV\python_310\lib\site-packages\nonebot\message.py", line 142, in _check_matcher await _run_matcher(Matcher, bot, event, state, stack, dependency_cache) File "D:\ENV\python_310\lib\site-packages\nonebot\message.py", line 188, in _run_matcher await matcher.run(bot, event, state, stack, dependency_cache)
File "D:\ENV\python_310\lib\site-packages\nonebot\internal\matcher\matcher.py", line 727, in run await self.simple_run(bot, event, state, stack, dependency_cache)
File "D:\ENV\python_310\lib\site-packages\nonebot\internal\matcher\matcher.py", line 702, in simple_run await handler( File "D:\ENV\python_310\lib\site-packages\nonebot\dependencies__init.py", line 108, in call__ return await cast(Callable[..., Awaitable[R]], self.call)(
values) File "E:\Project\QQrobot\test_bot.\nonebot_plugin_chatgpt\
init__.py", line 59, in ai_chat msg = await chat_bot(**session[event]).get_chat_response(text)
File "E:\Project\QQrobot\test_bot.\nonebot_plugin_chatgpt\chatgpt.py", line 94, in get_chat_response await self.refresh_session() File "E:\Project\QQrobot\test_bot.\nonebot_plugin_chatgpt\chatgpt.py", line 151, in refresh_session await self.refresh_session()

File "E:\Project\QQrobot\test_bot.\nonebot_plugin_chatgpt\chatgpt.py", line 156, in refresh_session self.authorization = response.json()["accessToken"] KeyError: 'accessToken' 12-14 21:10:47 [DEBUG] nonebot_plugin_chatgpt | 正在刷新session
12-14 21:10:48 [ERROR] nonebot_plugin_chatgpt | 刷新会话失败: HTTP200 {} Traceback (most recent call last): File "D:\ENV\python_310\lib\runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None, File "D:\ENV\python_310\lib\runpy.py", line 86, in _run_code exec(code, run_globals) File "D:\ENV\python_310\Scripts\nb.exe__main.py", line 7, in sys.exit(main()) File "D:\ENV\python_310\lib\site-packages\click\core.py", line 1130, in call return self.main(args, kwargs) File "D:\ENV\python_310\lib\site-packages\click\core.py", line 1055, in main rv = self.invoke(ctx) File "D:\ENV\python_310\lib\site-packages\click\core.py", line 1657, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "D:\ENV\python_310\lib\site-packages\click\core.py", line 1404, in invoke return ctx.invoke(self.callback, ctx.params) File "D:\ENV\python_310\lib\site-packages\click\core.py", line 760, in invoke return __callback(args, kwargs) File "D:\ENV\python_310\lib\site-packages\nb_cli\commands\main.py", line 30, in run run_bot(file, app) File "D:\ENV\python_310\lib\site-packages\nb_cli\handlers\deploy.py", line 25, in run_bot nonebot.run(app=f"{module_name}:{app}") File "D:\ENV\python_310\lib\site-packages\nonebot__init__.py", line 273, in run get_driver().run(*args, *kwargs) File "D:\ENV\python_310\lib\site-packages\nonebot\drivers\fastapi.py", line 172, in run uvicorn.run( File "D:\ENV\python_310\lib\site-packages\uvicorn\main.py", line 569, in run server.run() File "D:\ENV\python_310\lib\site-packages\uvicorn\server.py", line 60, in run return asyncio.run(self.serve(sockets=sockets)) File "D:\ENV\python_310\lib\asyncio\runners.py", line 44, in run
return loop.run_until_complete(main) File "D:\ENV\python_310\lib\asyncio\base_events.py", line 636, in run_until_complete self.run_forever() File "D:\ENV\python_310\lib\asyncio\windows_events.py", line 321, in run_forever super().run_forever() File "D:\ENV\python_310\lib\asyncio\base_events.py", line 603, in run_forever self._run_once() File "D:\ENV\python_310\lib\asyncio\base_events.py", line 1906, in _run_once handle._run() File "D:\ENV\python_310\lib\asyncio\events.py", line 80, in _run
self._context.run(self._callback,
self._args) File "D:\ENV\python_310\lib\site-packages\nonebot\message.py", line 142, in _check_matcher await _run_matcher(Matcher, bot, event, state, stack, dependency_cache) File "D:\ENV\python_310\lib\site-packages\nonebot\message.py", line 188, in _run_matcher await matcher.run(bot, event, state, stack, dependency_cache)
File "D:\ENV\python_310\lib\site-packages\nonebot\internal\matcher\matcher.py", line 727, in run await self.simple_run(bot, event, state, stack, dependency_cache)
File "D:\ENV\python_310\lib\site-packages\nonebot\internal\matcher\matcher.py", line 702, in simple_run await handler( File "D:\ENV\python_310\lib\site-packages\nonebot\dependencies__init.py", line 108, in call__ return await cast(Callable[..., Awaitable[R]], self.call)(
values) File "E:\Project\QQrobot\test_bot.\nonebot_plugin_chatgpt\
init__.py", line 59, in ai_chat msg = await chat_bot(**session[event]).get_chat_response(text)
File "E:\Project\QQrobot\test_bot.\nonebot_plugin_chatgpt\chatgpt.py", line 94, in get_chat_response await self.refresh_session() File "E:\Project\QQrobot\test_bot.\nonebot_plugin_chatgpt\chatgpt.py", line 156, in refresh_session self.authorization = response.json()["accessToken"] KeyError: 'accessToken' 12-14 21:10:48 [DEBUG] nonebot_plugin_htmlrender | 获取session失败,请 检查后台报错 12-14 21:10:48 [DEBUG] nonebot_plugin_htmlrender |

获取session失败, 请检查后台报错

ShanShuWu commented 1 year ago

我刚刚更新了插件,采取的上面的方法拿到的token,仍然是token失效

black-zero358 commented 1 year ago

token失效的错误是因为另外一个bug,在昨天另外一个pr修的,现在也已经合并

另外,我想询问一些细节问题, 在获取CHATGPT_SESSION_TOKEN的时候,代理是必须的吗,以及登录之后,再关闭代理是否会产生影响?

sena-nana commented 1 year ago

不要开代理,不要开代理,不要开代理 登陆的话必须开代理,然后关闭即可,只有登陆过程需要代理,刷新token不需要,插件运行也不需要

token失效的错误是因为另外一个bug,在昨天另外一个pr修的,现在也已经合并

另外,我想询问一些细节问题, 在获取CHATGPT_SESSION_TOKEN的时候,代理是必须的吗,以及登录之后,再关闭代理是否会产生影响?

sena-nana commented 1 year ago

@black-zero358 你可以改一下代码把返回的json print出来吗,我没有遇到过这个问题无法测试,不过似乎有很多人反应

black-zero358 commented 1 year ago

@black-zero358 你可以改一下代码把返回的json print出来吗,我没有遇到过这个问题无法测试,不过似乎有很多人反应

image image 空的

sena-nana commented 1 year ago

@black-zero358 你可以改一下代码把返回的json print出来吗,我没有遇到过这个问题无法测试,不过似乎有很多人反应

image image 空的

black-zero358 commented 1 year ago

@black-zero358 你可以改一下代码把返回的json print出来吗,我没有遇到过这个问题无法测试,不过似乎有很多人反应

image image 空的

在我刚刚用pycharm第一次运行时出现了"可能遇到了人工校验"的错误以及上面的json异常错误,第二次运行时只出现了json异常

lmst2 commented 1 year ago

我刚刚更新了插件,采取的上面的方法拿到的token,仍然是token失效

保持浏览器全屏,粘贴完了token启动机器人之后再确认一遍网站上的token有没有变,如果是一直没变的话不应该token失效的

black-zero358 commented 1 year ago

@black-zero358 你可以改一下代码把返回的json print出来吗,我没有遇到过这个问题无法测试,不过似乎有很多人反应

image image 空的

我删掉插件之后,直接把这个仓库拉下来放到plugins里运行就不会出问题了, 不知道是不是用命令安装存在延迟导致安装了旧的版本?

sena-nana commented 1 year ago

不排除这个可能 @black-zero358 能用就先用着吧,再出问题再说