Websockets 错误: ConnectionResetError: [Errno 104] Connection reset by peer
Posted
技术标签:
【中文标题】Websockets 错误: ConnectionResetError: [Errno 104] Connection reset by peer【英文标题】:Websockets Error: ConnectionResetError: [Errno 104] Connection reset by peer 【发布时间】:2021-07-08 08:49:04 【问题描述】:我无法在我的 PC 上运行此代码,但它在服务器上运行良好
import asyncio
import websockets
async def hello():
async with websockets.connect('wss://fstream.binance.com/stream?streams=ethusdt@depth5@100ms') as websocket:
while True:
msg = await websocket.recv()
print(msg)
asyncio.run(hello())
【问题讨论】:
如果您提供有关 PC 和服务器之间差异的信息会有所帮助,例如他们正在运行什么操作系统、python 版本等。这些信息可以帮助人们查明可能的原因。 【参考方案1】:这里有错误:
Traceback (most recent call last):
File "/home/johnxiong/PycharmProjects/mywork/tests.py", line 13, in <module>
asyncio.run(hello())
File "/home/johnxiong/anaconda3/envs/mywork/lib/python3.8/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/home/johnxiong/anaconda3/envs/mywork/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
return future.result()
File "/home/johnxiong/PycharmProjects/mywork/tests.py", line 7, in hello
async with websockets.connect('wss://fstream.binance.com/stream?streams=ethusdt@depth5@100ms') as websocket:
File "/home/johnxiong/anaconda3/envs/mywork/lib/python3.8/site-packages/websockets/py35/client.py", line 2, in __aenter__
return await self
File "/home/johnxiong/anaconda3/envs/mywork/lib/python3.8/site-packages/websockets/py35/client.py", line 12, in __await_impl__
transport, protocol = await self._creating_connection
File "/home/johnxiong/anaconda3/envs/mywork/lib/python3.8/asyncio/base_events.py", line 1050, in create_connection
transport, protocol = await self._create_connection_transport(
File "/home/johnxiong/anaconda3/envs/mywork/lib/python3.8/asyncio/base_events.py", line 1080, in _create_connection_transport
await waiter
File "/home/johnxiong/anaconda3/envs/mywork/lib/python3.8/asyncio/selector_events.py", line 848, in _read_ready__data_received
data = self._sock.recv(self.max_size)
ConnectionResetError: [Errno 104] Connection reset by peer
【讨论】:
这方面有什么更新吗?以上是关于Websockets 错误: ConnectionResetError: [Errno 104] Connection reset by peer的主要内容,如果未能解决你的问题,请参考以下文章
如何使实时服务器 Ratchet WebSockets 工作?