0

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:password@app-testing-3106893156.eu-central-1.bonsaisearch.net: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:password@app-testing-3106893156.eu-central-1.bonsaisearch.net: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?

agrajag_42
  • 155
  • 1
  • 12
  • Disclaimer: I never used Bonsai, so take this as a guess rather than an answer. It just looks like `os.environ` (not a dict but is a mapping object so it's similar) doesn't have that url as a key. Looking over the link you provided, I'm suspecting the string `'BONSAI_URL'` is intended to be the key, not a stand-in for a full url. Try the code without the edit, maybe? – BatWannaBe Apr 16 '20 at 08:16
  • if you want to run without setting ENV variable then just assign the url to bonsai variable. – Vikas Mulaje Apr 16 '20 at 08:19

1 Answers1

1

You have to set environment variable first. example

export BONSAI_URL='https://username:password@app-testing-3106893156.eu-central-1.bonsaisearch.net:443'

and then use it in code like

bonsai = os.environ['BONSAI_URL']

Check How to set environment variables in Python

Vikas Mulaje
  • 727
  • 6
  • 11