The Key Error is originating from the os.environ method, which is expecting a string that matches an environment variable. You can read more about this by checking out the Python documentation for os.environ.
Check out the Examples section of the M2X Python cliient library for documentation on usage of the examples.
You can bypass the usage of os.environ entirely as well, though it's not advised to store your API key directly in code. To do this, revise the offending line as follows: