Raise KeyError(key) from None

Hi, I am following this instruction:

but I am getting this error: (vscode)
[2024-02-28 16:49:02,342] ERROR in app: Exception on / [GET]
Traceback (most recent call last):
File “C:\Users\mark\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\flask\app.py”, line 1463, in wsgi_app
response = self.full_dispatch_request()
File “C:\Users\mark\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\flask\app.py”, line 872, in full_dispatch_request
rv = self.handle_user_exception(e)
File “C:\Users\mark\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\flask\app.py”, line 870, in full_dispatch_request
rv = self.dispatch_request()
File “C:\Users\mark\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\flask\app.py”, line 855, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return]
File “C:\g2\test_sg_ami.py”, line 13, in home
File “C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\lib\os.py”, line 680, in getitem
raise KeyError(key) from None
KeyError: ‘FLASK_SCRIPT_NAME’ - - [28/Feb/2024 16:49:02] “GET / HTTP/1.1” 500 -

any ideas?

i did set both like so:
set FLASK_SCRIPT_NAME=“test_sg_ami.py”
set FLASK_SCRIPT_KEY=“4ckyuwC-vcmkahunxkksrgqkv”

Where did you set the varables?
Because it seems like your script can’t access them.

hi Ricardo,
I set them here in the python file:

as well as in Terminal in vsCode by doing:
set FLASK_SCRIPT_NAME=“test_sg_ami.py”
set FLASK_SCRIPT_KEY=“4ckyuwC-vcmkahunxkksrgqkv”


i can get it running with following:

but not how the channel instructed:


  1. Please don’t post your script name and key on any public forum, a bad actor would now only need your Shotgrid URl to gain admin access to your site.
    You should invalidate/remove the script user immediatly and recreate it.


This refers to searching the environment for these keys and their value.
This only works if you set these environments on the machine or on the fly.
If you run this from VS Code then either you need to ensure VS code sets these when you run your file or the machine itself has these environment variables set.

Also, not sure why you have a comma after the first line, you should remove that.

thx Rica.

that key was not a real one but thx for bring that up! ^^

I certainly can look into the vs code and env settings. thx again.

1 Like