Search code examples
pythonpython-3.xiotnats.io

nats: no ssl context provided


Passing credentials to connect to ngs global Nats server causes exception:

2022-08-22 11:46:51,755 ERROR: nats: encountered error
Traceback (most recent call last):
  File "/home/devaxe/.pyenv/versions/3.10.4/lib/python3.10/site-packages/nats/aio/client.py", line 419, in connect
    await self._process_connect_init()
  File "/home/devaxe/.pyenv/versions/3.10.4/lib/python3.10/site-packages/nats/aio/client.py", line 1792, in _process_connect_init
    raise errors.Error('nats: no ssl context provided')

Here is code thats raises error:

async def init_nats():
  global ns
  try:
    ns = await nats.connect('connect.ngs.global', user_credentials=NATS_CREDS) if not _DEBUG \
    else await nats.connect("nats://localhost:4222")

    return ns
  except Exception as e:
    print(f"[init_nats] Could not connect to NATS server. {e}")
    return None

_DEBUG is just constant bool.

def main():
  global _DEBUG
  if len(sys.argv) == 2 and sys.argv[1] == '-d':
    _DEBUG = True

I can easily connect to local nats server, but can't connect to remote. I've no clue what's wrong with my code. 0_o

There is no results in google search for "nats: no ssl context provided"...


Solution

  • You can try with nats.connect('tls://connect.ngs.global') when connecting (using a scheme prefix).