Код: Выделить всё
"raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://www.notion.so/api/v3/loadUserContent"
Я написал здесь полный код (очевидно, не добавленный мой ключ введен, однако я дважды проверил, что использую правильный ключ интеграции, и также обновил его)
Код: Выделить всё
from notion.client import NotionClient
# Your integration token
integration_token = "MYKEY"
# Authenticate with Notion API
client = NotionClient(token_v2=integration_token)
# Create a new page
calendar_page = client.get_user().get_workspace().add_page(title="365-Day Calendar")
# Create a table block
calendar_table = calendar_page.children.add_new("collection_view")
# Set up the schema for the table
calendar_table.collection = client.get_collection("block")
calendar_table.views.add_new(view_type="table")
schema = calendar_table.collection.add_schema_properties({"Name": {"type": "title"}})
# Add a property for mood
schema = calendar_table.collection.add_schema_properties({"Mood": {"type": "select", "options": [
{"name": "😊 Good"}, {"name": "😞 Bad"}
]}})
# Update each row with the Mood property
for row in calendar_table.collection.get_rows():
row.set_property("Mood", "😊 Good") # Set default mood to Good
# Add a property for month
schema = calendar_table.collection.add_schema_properties({"Month": {"type": "select", "options": [
{"name": "January"}, {"name": "February"}, {"name": "March"}, {"name": "April"}, {"name": "May"}, {"name": "June"},
{"name": "July"}, {"name": "August"}, {"name": "September"}, {"name": "October"}, {"name": "November"}, {"name": "December"}
]}})
# Update each row with the Month property
for row in calendar_table.collection.get_rows():
# Extract month from the date
month = row.title.split('-')[1]
row.set_property("Month", month)
# Add title with the year
calendar_table.title = "2024"
Подробнее здесь: https://stackoverflow.com/questions/784 ... orrect-key