Skip to content

Commit 005f1c0

Browse files
simplify echo.py
1 parent d6ee047 commit 005f1c0

File tree

1 file changed

+5
-26
lines changed
  • internal_filesystem/apps/com.example.btcticker/assets

1 file changed

+5
-26
lines changed
Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,13 @@
1-
import sys
21
import ssl
3-
4-
# ruff: noqa: E402
5-
sys.path.insert(0, ".")
62
import aiohttp
73
import asyncio
84

9-
try:
10-
URL = sys.argv[1] # expects a websocket echo server
11-
except Exception:
12-
# URL = "ws://echo.websocket.events" # also works
13-
URL = "wss://echo.websocket.events"
14-
15-
16-
sslctx = False
17-
18-
if URL.startswith("wss:"):
19-
try:
20-
sslctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
21-
sslctx.verify_mode = ssl.CERT_NONE
22-
#sslctx.verify_mode = ssl.CERT_REQUIRED # doesn't work because OSError: (-30336, 'MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED')
23-
except Exception:
24-
pass
25-
5+
sslctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
6+
sslctx.verify_mode = ssl.CERT_NONE
7+
#sslctx.verify_mode = ssl.CERT_REQUIRED # doesn't work because OSError: (-30336, 'MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED')
268

279
async def ws_test_echo(session):
28-
async with session.ws_connect(URL, ssl=sslctx) as ws:
10+
async with session.ws_connect("wss://echo.websocket.events", ssl=sslctx) as ws:
2911
await ws.send_str("hello world!\r\n")
3012
async for msg in ws:
3113
if msg.type == aiohttp.WSMsgType.TEXT:
@@ -35,11 +17,8 @@ async def ws_test_echo(session):
3517
await ws.send_str("close\r\n")
3618
await ws.close()
3719

38-
3920
async def main():
4021
async with aiohttp.ClientSession() as session:
4122
await ws_test_echo(session)
4223

43-
44-
if __name__ == "__main__":
45-
asyncio.run(main())
24+
asyncio.run(main())

0 commit comments

Comments
 (0)