KeyError when I try to connect the Client #23
-
Hi! First, I would like to thank you for creating this library. I had a problem when I was trying to follow along with the README and I keep receiving a "KeyError" when I try to connect the notion Client. I've included an image below. The token is for some test integration I made just for this purpose so I don't mind if anyone wants to experiment with it. I tried the code on Google Colab to ensure that the problem wasn't just my computer. Any help would be appreciated! Edit by ramnes: I modified the image to mask the secret token. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
I believe you need TOKEN to be in quotations
|
Beta Was this translation helpful? Give feedback.
-
The idea is that you shouldn't hardcode a token, but use environment variables instead. You can read more on this here: https://12factor.net/config In your situation, that means removing the |
Beta Was this translation helpful? Give feedback.
-
The best way to store secrets is a Create a VARIABLE=val
NOTION_TOKEN=secret_abcdefgh1234 In your python code, you need to load the variables defined in the # settings.py
import os
from dotenv import load_dotenv # pip install python-dotenv
load_dotenv()
VARIABLE = os.getenv("VARIABLE")
NOTION_TOKEN = os.getenv("NOTION_TOKEN") You can import and use these variables in your python module where you actually need them. # script.py
from notion_client import Client
import settings
# in this scope you can use the variables defined in settings.py
print(settings.VARIABLE) # don't print secrets
notion = Client(auth=settings.NOTION_TOKEN)
# ... |
Beta Was this translation helpful? Give feedback.
I believe you need TOKEN to be in quotations