Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: 2.8 SSE 连接超时 #1950

Closed
2 tasks done
shui9527 opened this issue Jun 17, 2024 · 3 comments
Closed
2 tasks done

[Bug]: 2.8 SSE 连接超时 #1950

shui9527 opened this issue Jun 17, 2024 · 3 comments

Comments

@shui9527
Copy link

解决方案检查

预期行为

我想要通过SSE 获取播放器状态,但是运行一会就会中断,之前配合v2.7 使用时是正常的,更新到2.8以后出现了这个问题。

实际行为

Traceback (most recent call last):
File "E:\Users\shuis\python\LiveToolBox\monitevent.py", line 13, in run
loop.run_until_complete(self.process_data())
File "D:\Anaconda3\Lib\asyncio\base_events.py", line 653, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "E:\Users\shuis\python\LiveToolBox\monitevent.py", line 29, in process_data
async for event in self.get_data():
File "E:\Users\shuis\python\LiveToolBox\monitevent.py", line 20, in get_data
line = await response.content.readline()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Anaconda3\Lib\site-packages\aiohttp\streams.py", line 307, in readline
return await self.readuntil()
^^^^^^^^^^^^^^^^^^^^^^
File "D:\Anaconda3\Lib\site-packages\aiohttp\streams.py", line 341, in readuntil
await self._wait("readuntil")
File "D:\Anaconda3\Lib\site-packages\aiohttp\streams.py", line 301, in _wait
with self._timer:
File "D:\Anaconda3\Lib\site-packages\aiohttp\helpers.py", line 735, in exit
raise asyncio.TimeoutError from None
TimeoutError

Lx Music 版本

2.8

最后正常的版本

2.7

操作系统版本

Windows 10 22H2 19045.4529

附加信息

class LXSSEThread(QThread):
data_updated = Signal(str)

def run(self):
    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)
    loop.run_until_complete(self.send_data())

async def get_data(self):
    async with aiohttp.ClientSession() as session:
        try:
            async with session.get("https://localhost:23330/subscribe-player-status") as response:
                
                while True:
                    line = await response.content.readline()
                    event = str(line.decode('utf-8').strip())

                    yield event
        except aiohttp.ClientConnectorError:
            event = '无法连接播放器 : 请确认已打开LX播放器'
            yield event

async def send_data(self):
    async for event in self.get_data():
        self.data_updated.emit(event)
@lyswhut
Copy link
Owner

lyswhut commented Jun 18, 2024

2.8.0不影响这个,你这个是请求超时,确保服务是否已经启动成功,可以去开放API设置看有没有报错信息,同时浏览器、curl之类的客户端是否可以访问SSE地址

@shui9527
Copy link
Author

我使用浏览器访问也会出现拒绝连接请求。

不知道是什么问题

开放API设置 没看到有报错信息

QQ截图20240619021235

@lyswhut
Copy link
Owner

lyswhut commented Jun 19, 2024

/status 接口是否可以正常访问?如果可以,那可能请求经过了某些中间软件的除了导致的?
如果不可以,检查是否被第三方软件之类的拦截?或者尝试更换端口号?
还可以去到软件安装目录,用命令行启动软件,看看有没有可能相关的日志输出(但大概率会没有
再不行再退回2.7.0试试?2.8.0就增加了一个允许跨域的响应头,正常情况下应该跟这个没关系

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants