Skip to content
Advertisement

Key error while running a Python program with getitem

The code below creates this error when ran on Amazon Linux 2. The intent is to have the python program respond to user input from a discord server. I know just enough to get me here about python. Any help is appreciated. They server is running an updated version of Amazon Linux 2.

JavaScript

JavaScript

Advertisement

Answer

You are trying to read from a system environment variable, which clearly hasn’t been set hence the KeyError (as SuperSecretSquirrelStuff-key doesn’t exist as a key in os.environ).

I can see that you’ve used the config object before to read, for example, instance_id.

In that case, read directly from your configuration instead of doing os.environ if you want the value of discord_key:

client.run(config.discord_key)


Or alternatively (not sure why you would like to do this) set the environment variable before reading it:

JavaScript
Advertisement