# Raise KeyError(key) from None

**URL:** <https://community.shotgridsoftware.com/t/raise-keyerror-key-from-none/18488>\
**Category:** Pipeline Integrations\
**Tags:** ami\
**Created:** [February 29, 2024, 12:55am UTC](https://community.shotgridsoftware.com/t/raise-keyerror-key-from-none/18488 "2024-02-29T00:55:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![unicorn](https://avatars.discourse-cdn.com/v4/letter/u/35a633/32.png) [@unicorn](https://community.shotgridsoftware.com/u/unicorn)\
**Post date:** [February 29, 2024, 12:55am UTC](https://community.shotgridsoftware.com/t/raise-keyerror-key-from-none/18488/1 "2024-02-29T00:55:51Z")

</div>

Hi, I am following this instruction:

[![](https://global.discourse-cdn.com/shotgunsoftware/original/2X/9/9884f9f30df773de6b9d439f1835ae313e2cb6e5.jpeg "Developer Training - Shotgun: Creating, Testing, and Debugging Action Menu Items") ](https://www.youtube.com/watch?v=u3u8pL9o-as)

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  
script\_name=os.environ[“FLASK\_SCRIPT\_NAME”],  
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’  
127.0.0.1 - - [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”

---

<div class="post-metadata">

**Author:** ![Ricardo\_Musch](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/ricardo_musch/32/405_2.png) [@Ricardo\_Musch](https://community.shotgridsoftware.com/u/Ricardo_Musch)\
**Post date:** [March 1, 2024, 5:36pm UTC](https://community.shotgridsoftware.com/t/raise-keyerror-key-from-none/18488/2 "2024-03-01T17:36:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![unicorn](https://avatars.discourse-cdn.com/v4/letter/u/35a633/32.png) [@unicorn](https://community.shotgridsoftware.com/u/unicorn)\
**Post date:** [March 1, 2024, 7:52pm UTC](https://community.shotgridsoftware.com/t/raise-keyerror-key-from-none/18488/3 "2024-03-01T19:52:36Z")

</div>

hi Ricardo,  
I set them here in the python file:  
script\_name=os.environ[“FLASK\_SCRIPT\_NAME”],  
api\_key=os.environ[“FLASK\_SCRIPT\_KEY”],

as well as in Terminal in vsCode by doing:  
set FLASK\_SCRIPT\_NAME=“test\_sg\_ami.py”  
set FLASK\_SCRIPT\_KEY=“4ckyuwC-vcmkahunxkksrgqkv”

regards,

---

<div class="post-metadata">

**Author:** ![unicorn](https://avatars.discourse-cdn.com/v4/letter/u/35a633/32.png) [@unicorn](https://community.shotgridsoftware.com/u/unicorn)\
**Post date:** [March 1, 2024, 8:16pm UTC](https://community.shotgridsoftware.com/t/raise-keyerror-key-from-none/18488/4 "2024-03-01T20:16:25Z")

</div>

i can get it running with following:  
script\_name=“test\_sg\_ami”,  
api\_key=“4ckyuwC-vcmkahunxkksrgqkv”,

but not how the channel instructed:  
script\_name=os.environ[“FLASK\_SCRIPT\_NAME”],  
api\_key=os.environ[“FLASK\_SCRIPT\_KEY”],

thoughts?

---

<div class="post-metadata">

**Author:** ![Ricardo\_Musch](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/ricardo_musch/32/405_2.png) [@Ricardo\_Musch](https://community.shotgridsoftware.com/u/Ricardo_Musch)\
**Post date:** [March 4, 2024, 3:37am UTC](https://community.shotgridsoftware.com/t/raise-keyerror-key-from-none/18488/5 "2024-03-04T03:37:08Z")

</div>

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.

2. 

```python
script_name=os.environ[“FLASK_SCRIPT_NAME”],
api_key=os.environ[“FLASK_SCRIPT_KEY”]

```

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.

---

<div class="post-metadata">

**Author:** ![unicorn](https://avatars.discourse-cdn.com/v4/letter/u/35a633/32.png) [@unicorn](https://community.shotgridsoftware.com/u/unicorn)\
**Post date:** [March 4, 2024, 3:49am UTC](https://community.shotgridsoftware.com/t/raise-keyerror-key-from-none/18488/6 "2024-03-04T03:49:50Z")

</div>

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.
