最近拿 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.')