Search code examples
pythonbonsai-elasticsearch

Connect Python to Bonsai


I am trying to connect to Bonsai using Python and for this I am using the code provided by Bonsai here. However, my code breaks at

bonsai = os.environ['https://username:[email protected]:443']

with error

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/usr/lib/python3.7/os.py", line 679, in __getitem__
    raise KeyError(key) from None
KeyError: 'https://username:[email protected]:443'

I am using the exact same code Bonsai provides and I am only adding the Full Access URL also provided by Bonsai so I have no idea how to proceed with this. Any ideas what is causing the error?


Solution

  • You have to set environment variable first. example

    export BONSAI_URL='https://username:[email protected]:443'
    

    and then use it in code like

    bonsai = os.environ['BONSAI_URL']
    

    Check How to set environment variables in Python