Error in Connecting to Websockets

Subscription code : 15
/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/dhanhq/marketfeed.py:79: RuntimeWarning: coroutine ‘DhanFeed.connect’ was never awaited
self.connect()
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Traceback (most recent call last):
File “/Users/ujasthakkar/Desktop/tt/ws.py”, line 38, in
feed.run_forever()
File “/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/dhanhq/marketfeed.py”, line 83, in run_forever
self.loop.run_until_complete(self.connect())
File “/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/base_events.py”, line 653, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File “/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/dhanhq/marketfeed.py”, line 88, in connect
self.ws = await websockets.connect(WSS_URL)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/websockets/legacy/client.py”, line 659, in await_impl_timeout
return await asyncio.wait_for(self.await_impl(), self.open_timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/tasks.py”, line 479, in wait_for
return fut.result()
^^^^^^^^^^^^
File “/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/websockets/legacy/client.py”, line 663, in await_impl
_transport, _protocol = await self._create_connection()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/base_events.py”, line 1106, in create_connection
transport, protocol = await self._create_connection_transport(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/base_events.py”, line 1139, in _create_connection_transport
await waiter
File “/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/sslproto.py”, line 574, in _on_handshake_complete
raise handshake_exc
File “/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/sslproto.py”, line 556, in _do_handshake
self._sslobj.do_handshake()
File “/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/ssl.py”, line 979, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:992)

Getting this error when connecting to websocket, not sure why is it coming, the process kills and exits when I run the code.

Hello @thakkarujas5

Welcome to Dhan Community!

This looks like a handshake certificate requirement for your local python configuration. You can look at this for more information on the issue:

You can go through the link which shared by @Hardik and there is another possibility which is that , if you are using some sort of Corporate Machine or using some kind of Proxy System and due to that it could be possible to get certificate error.

The solution worked, thank you!!

2 Likes