MerkulovDaniil / notion4ever

šŸ› Python tool for export all your content of Notion page using official Notion API. Includes: all nested subpages, markdown files and HTMLs, nice urls, downloading locally all its content.
MIT License
135 stars 9 forks source link

KeyError #3

Open techyogi opened 2 years ago

techyogi commented 2 years ago

trying to pull an entire workspace, so using the pageid of the workspace page. Always getting "KeyError" as follows:

2022-02-04 09:29:32,033 INFO: šŸ¤– Notion authentification completed successfully. 2022-02-04 09:29:32,034 INFO: šŸ¤– Started raw notion content parsing. 2022-02-04 09:29:38,845 INFO: šŸ¤– Downloaded raw notion content. Saved at ./notion_content.json 2022-02-04 09:29:38,845 INFO: šŸ¤– Started structuring notion data Traceback (most recent call last): File "/opt/homebrew/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 197, in _run_module_as_main return _run_code(code, main_globals, None, File "/opt/homebrew/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code exec(code, run_globals) File "/Users/techyogi/Desktop/notion4ever/notion4ever/main.py", line 102, in main() File "/Users/techyogi/Desktop/notion4ever/notion4ever/main.py", line 74, in main structured_notion = structuring.structurize_notion_content(raw_notion, File "/Users/techyogi/Desktop/notion4ever/notion4ever/structuring.py", line 495, in structurize_notion_content markdown_parser.parse_markdown(raw_notion, structured_notion) File "/Users/techyogi/Desktop/notion4ever/notion4ever/markdown_parser.py", line 372, in parse_markdown page_md = blocks_convertor(raw_notion[page_id]["blocks"], structured_notion, page_id) File "/Users/techyogi/Desktop/notion4ever/notion4ever/markdown_parser.py", line 139, in blocks_convertor block_md = block_convertor(block,0, structured_notion, page_id) File "/Users/techyogi/Desktop/notion4ever/notion4ever/markdown_parser.py", line 238, in block_convertor block_md = block_convertor(block, depth, structured_notion, page_id) File "/Users/techyogi/Desktop/notion4ever/notion4ever/markdown_parser.py", line 238, in block_convertor block_md = block_convertor(block, depth, structured_notion, page_id) File "/Users/techyogi/Desktop/notion4ever/notion4ever/markdown_parser.py", line 188, in block_convertor title = structured_notion['pages'][block['id']]['title'] KeyError: 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'

MerkulovDaniil commented 2 years ago

Indeed, the code was designed to work with some specific page with all nested content inside the page. Need to add the option for exporting the whole workspace.

Kourai commented 2 years ago

Hello ! Kind of a similar problem here : I tryied to pull a regular page (no subpage, no database) But I'm also getting a "KeyError'

2022-06-21 19:13:06,788 INFO: šŸ¤– Started structuring notion data Traceback (most recent call last): File "/opt/hostedtoolcache/Python/3.10.0/x64/lib/python3.10/runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None, File "/opt/hostedtoolcache/Python/3.10.0/x64/lib/python3.10/runpy.py", line 86, in _run_code exec(code, run_globals) File "/home/runner/work/notionexport/notionexport/notion4ever/main.py", line 109, in main() File "/home/runner/work/notionexport/notionexport/notion4ever/main.py", line 81, in main structured_notion = structuring.structurize_notion_content(raw_notion, File "/home/runner/work/notionexport/notionexport/notion4ever/structuring.py", line 500, in structurize_notion_content markdown_parser.parse_markdown(raw_notion, structured_notion) File "/home/runner/work/notionexport/notionexport/notion4ever/markdown_parser.py", line 376, in parse_markdown page_md = blocks_convertor(raw_notion[page_id]["blocks"], structured_notion, page_id) File "/home/runner/work/notionexport/notionexport/notion4ever/markdown_parser.py", line 140, in blocks_convertor block_md = block_convertor(block,0, structured_notion, page_id) File "/home/runner/work/notionexport/notionexport/notion4ever/markdown_parser.py", line 239, in block_convertor block_md = block_convertor(block, depth, structured_notion, page_id) File "/home/runner/work/notionexport/notionexport/notion4ever/markdown_parser.py", line 239, in block_convertor block_md = block_convertor(block, depth, structured_notion, page_id) File "/home/runner/work/notionexport/notionexport/notion4ever/markdown_parser.py", line 206, in block_convertor block_type_map[block_type](information_collector(block[block_type], File "/home/runner/work/notionexport/notionexport/notion4ever/markdown_parser.py", line 151, in information_collector information['icon'] = payload['icon']['emoji'] KeyError: 'emoji' Error: Process completed with exit code 1.

I Guess the culprit is quite obvious here : THE EMOJI ! I had a custom emoji on the page (Added by using the Upload/Link function from notion emoji), and now it run fine ! ;)

Frekido commented 1 year ago

Dear MerkuloDanii, First of all, thank for this nice project! I also have a KeyError. Have you allready found a way to export the whole workspace, without heving to specify a Page_id? Thanks!

asmodat commented 1 year ago

The same issue found here:

2022-12-21 07:[11](https://github.com/KiraCore/docs.kira.network/actions/runs/3747180944/jobs/6363161943#step:9:12):17,725 INFO: šŸ¤– Notion authentification completed successfully.
2022-[12](https://github.com/KiraCore/docs.kira.network/actions/runs/3747180944/jobs/6363161943#step:9:13)-21 07:11:17,725 INFO: šŸ¤– Started raw notion content parsing.
2022-12-21 07:11:18,468 INFO: šŸ¤– Downloaded raw notion content. Saved at ./notion_content.json
2022-12-21 07:11:18,468 INFO: šŸ¤– Started structuring notion data
Traceback (most recent call last):
  File "/__t/Python/3.10.0/x64/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/__t/Python/3.10.0/x64/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/__w/docs.kira.network/docs.kira.network/notion4ever/__main__.py", line 109, in <module>
    main()
  File "/__w/docs.kira.network/docs.kira.network/notion4ever/__main__.py", line 81, in main
    structured_notion = structuring.structurize_notion_content(raw_notion,
  File "/__w/docs.kira.network/docs.kira.network/notion4ever/structuring.py", line 489, in structurize_notion_content
    structured_notion["pages"] = parse_headers(raw_notion)
  File "/__w/docs.kira.network/docs.kira.network/notion4ever/structuring.py", line [16](https://github.com/KiraCore/docs.kira.network/actions/runs/3747180944/jobs/6363161943#step:9:17)3, in parse_headers
    notion_pages[parent_id]["children"].append(page_id)
KeyError: 'b6[17](https://github.com/KiraCore/docs.kira.network/actions/runs/3747180944/jobs/6363161943#step:9:18)XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXSANITIZEDXXXXXXXXXXXXX'