跳转到内容
彼岸论坛
欢迎抵达彼岸 彼岸花开 此处谁在 -彼岸论坛

[Python] [新手求助] (可能是)websocket 的代理问题


小天管理

已推荐帖子

最近拿 python 写了一个访问实时币价的小脚本,在单位电脑上正常运行,但是在家里的电脑上会访问超时,似乎是代理的问题(试过访问墙内 ws 是没问题的),但是没有印象单位和家里电脑代理设置有什么不同,特来求助大佬

用的 python 的 aiowebsocket 库,翻了下代码是在 ssl 握手的时候超时造成的,但是文档没看到代理相关设置,clash 里使用的混合端口设置也未发现可能的问题

错误信息:
Traceback (most recent call last):
File "C:\Users\xxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\websockets\legacy\client.py", line 647, in __await_impl_timeout__
return await self.__await_impl__()
^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "C:\Users\xxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\websockets\legacy\client.py", line 651, in __await_impl__
_transport, _protocol = await self._create_connection()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "C:\Users\xxx\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 1069, in create_connection
sock = await self._connect_sock(
^^^^^^^^^^^^^^^^^^^^^^^^^

File "C:\Users\xxx\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 973, in _connect_sock
await self.sock_connect(sock, address)
File "C:\Users\xxx\AppData\Local\Programs\Python\Python311\Lib\asyncio\proactor_events.py", line 726, in sock_connect
return await self._proactor.connect(sock, address)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "C:\Users\xxx\Desktop\1\p.py", line 15, in <module>
asyncio.get_event_loop().run_until_complete(clientRun())
File "C:\Users\xxx\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 653, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^

File "C:\Users\xxx\Desktop\1\p.py", line 5, in clientRun
async with websockets.connect('wss://stream.binance.com/stream') as websocket:
File "C:\Users\xxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\websockets\legacy\client.py", line 629, in __aenter__
return await self
^^^^^^^^^^
File "C:\Users\xxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\websockets\legacy\client.py", line 646, in __await_impl_timeout__
async with asyncio_timeout(self.open_timeout):
File "C:\Users\xxx\AppData\Local\Programs\Python\Python311\Lib\asyncio\timeouts.py", line 111, in __aexit__
raise TimeoutError from exc_val
TimeoutError

代码:
import asyncio
import logging
from aiowebsocket.converses import AioWebSocket
import json

async def startup(uri):
async with AioWebSocket(uri) as aws:
converse = aws.manipulator
await converse.send('{"method":"SUBSCRIBE","params":["!miniTicker@arr@3000ms"],"id":1}')
while True:
mes = await converse.receive()
# print(json.loads(mes.decode()))

if __name__ == '__main__':
remote = 'wss://stream.binance.com/stream'
try:
asyncio.get_event_loop().run_until_complete(startup(remote))
except KeyboardInterrupt as exc:
logging.info('Quit.')
意见的链接
分享到其他网站

加入讨论

您现在可以发表并稍后注册. 如果您是会员,请现在登录来参与讨论.

游客
回复主题...

×   粘贴为富文本.   粘贴为纯文本来代替

  只允许使用75个表情符号.

×   您的链接已自动嵌入.   显示为链接来代替

×   您之前的内容已恢复.   清除编辑器

×   您无法直接粘贴图片.要从网址上传或插入图片.

  • 游客注册

    游客注册

  • 会员

  • 最新的状态更新

    没有最新的状态更新
  • 最近查看

    • 没有会员查看此页面.
×
×
  • 创建新的...