md2notion_api_version icon indicating copy to clipboard operation
md2notion_api_version copied to clipboard

Key Error: "Name"

Open Fanisting opened this issue 2 years ago • 1 comments

I got the following error while uploading:

Traceback (most recent call last):
  File "E:\OneDrive - zju.edu.cn\桌面\md2notion\md2notion_api_version\main.py", line 40, in <module>
    client      = NotionSyncDatabase(connection_key, database_id)
  File "E:\OneDrive - zju.edu.cn\桌面\md2notion\md2notion_api_version\NotionClient.py", line 12, in __init__
    if len(page['properties']['Name']['title'])==0:continue
KeyError: 'Name'

Fanisting avatar May 06 '23 21:05 Fanisting

The full code is

full_or_partial_pages = self.notion.databases.query(database_id=self.database_id)
        self.file_names   = {}
        for page in full_or_partial_pages["results"]:
            if not is_full_page(page):continue
            if len(page['properties']['Name']['title'])==0:continue
            page_title = page['properties']['Name']['title'][0]['plain_text']
            if  page_title not in self.file_names:
                self.file_names[page_title] = 1
            else:
                print(f"WARNING: detect repeat file names:{page_title}")

The database_id should directly point to a notion database, and I suppose you point to the whole project or another page.

for page in full_or_partial_pages["results"]: will scan the database and report how many items in the database. The error line KeyError: 'Name' means the scaned page is not a element in a database.

veya2ztn avatar May 07 '23 13:05 veya2ztn