将Python连接到盆景



我正在尝试使用Python连接到Bonsai,为此我使用了Bonsai提供的代码。然而,我的代码在处中断

bonsai = os.environ['https://username:password@app-testing-3106893156.eu-central-1.bonsaisearch.net:443']

错误

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'

我使用的代码与盆景提供的代码完全相同,我只是添加了盆景提供的完全访问URL,所以我不知道如何继续。你知道是什么导致了这个错误吗?

您必须首先设置环境变量。示例

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

然后在类似的代码中使用

bonsai = os.environ['BONSAI_URL']

检查如何在Python 中设置环境变量

最新更新