1111from .exceptions import ConnectionClosed
1212from .frames import Close
1313from .streams import StreamReader
14+ from .uri import parse_uri
1415from .version import version as websockets_version
1516
1617
@@ -101,9 +102,14 @@ async def send_outgoing_messages(
101102 break
102103
103104
104- async def interactive_client (uri : str ) -> None :
105+ async def interactive_client (uri : str , insecure : bool = False ) -> None :
105106 try :
106- websocket = await connect (uri )
107+ if insecure and parse_uri (uri ).secure :
108+ import ssl
109+
110+ websocket = await connect (uri , ssl = ssl ._create_unverified_context ())
111+ else :
112+ websocket = await connect (uri )
107113 except Exception as exc :
108114 print (f"Failed to connect to { uri } : { exc } ." )
109115 sys .exit (1 )
@@ -151,6 +157,9 @@ def main(argv: list[str] | None = None) -> None:
151157 group = parser .add_mutually_exclusive_group ()
152158 group .add_argument ("--version" , action = "store_true" )
153159 group .add_argument ("uri" , metavar = "<uri>" , nargs = "?" )
160+
161+ parser .add_argument ("--insecure" , action = "store_true" )
162+
154163 args = parser .parse_args (argv )
155164
156165 if args .version :
@@ -173,6 +182,6 @@ def main(argv: list[str] | None = None) -> None:
173182
174183 # Remove the try/except block when dropping Python < 3.11.
175184 try :
176- asyncio .run (interactive_client (args .uri ))
185+ asyncio .run (interactive_client (args .uri , insecure = args . insecure ))
177186 except KeyboardInterrupt : # pragma: no cover
178187 pass
0 commit comments