echo724 / notion2md

Notion Markdown Exporter with Python Cli
MIT License
682 stars 54 forks source link

KeyError: 'text' #18

Closed Kin-Zhang closed 2 years ago

Kin-Zhang commented 2 years ago

System:

Here is the error show on python, I tried a simple page it works but with other more complex page have many blocks, it seems have problems: image And here is the error text:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/kin/anaconda3/envs/py37/lib/python3.7/site-packages/notion2md/exporter.py", line 18, in block_exporter
    output.write(blocks_convertor(blocks))
  File "/home/kin/anaconda3/envs/py37/lib/python3.7/site-packages/notion2md/convertor/block.py", line 109, in blocks_convertor
    outcome_blocks = "".join([result for result in results])
  File "/home/kin/anaconda3/envs/py37/lib/python3.7/site-packages/notion2md/convertor/block.py", line 109, in <listcomp>
    outcome_blocks = "".join([result for result in results])
  File "/home/kin/anaconda3/envs/py37/lib/python3.7/concurrent/futures/_base.py", line 598, in result_iterator
    yield fs.pop().result()
  File "/home/kin/anaconda3/envs/py37/lib/python3.7/concurrent/futures/_base.py", line 428, in result
    return self.__get_result()
  File "/home/kin/anaconda3/envs/py37/lib/python3.7/concurrent/futures/_base.py", line 384, in __get_result
    raise self._exception
  File "/home/kin/anaconda3/envs/py37/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/kin/anaconda3/envs/py37/lib/python3.7/site-packages/notion2md/convertor/block.py", line 140, in block_convertor
    outcome_block = block_type_map[block_type](information_collector(block[block_type])) + "\n\n"
  File "/home/kin/anaconda3/envs/py37/lib/python3.7/site-packages/notion2md/convertor/block.py", line 115, in information_collector
    information['text'] = richtext_convertor(payload['text'])
  File "/home/kin/anaconda3/envs/py37/lib/python3.7/site-packages/notion2md/convertor/richtext.py", line 48, in richtext_convertor
    outcome_word = link(richtext["text"])
KeyError: 'text'
echo724 commented 2 years ago

Oh thank you for sharing the error. Can you share the notion page url that you tested? It will be more easy to find which block occurs error.

Kin-Zhang commented 2 years ago

Oh thank you for sharing the error. Can you share the notion page url that you tested? It will be more easy to find which block occurs error.

Thanks for your quick reply, here is the page: https://kinzhang.notion.site/Optimization-Based-Collision-Avoidance-815a2796158b41c4990fa9a04272e9a4 Just ignore the language...

Kin-Zhang commented 2 years ago

I think the error may be it didn't support all kinds of the block that notion have... but the notion export button to markdown is fine, just sometimes the format is terrible with tab especially.

Kin-Zhang commented 2 years ago

here is the config script:

from notion2md.exporter import block_exporter
class config:
    def __init__(self, id, path, name):
        self.target_id = id
        self.output_path = path
        self.file_name = name
my_config = config("815a2796158b41c4990fa9a04272e9a4","/home/kin/MyBlog/content/posts","test")
block_exporter(my_config)
echo724 commented 2 years ago

Yeap. I found that I didn't add the handling case for "mention" type richtext. I add it and it will work well now. I will release new version that fixes this. Thank you p.s. I changed the tap to \t

Kin-Zhang commented 2 years ago

Yeap. I found that I didn't add the handling case for "mention" type richtext. I add it and it will work well now. I will release new version that fixes this. Thank you p.s. I changed the tap to \t

 Retrieving blocks from '815a2796158b41c4990fa9a04272e9a4'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/kin/anaconda3/envs/py37/lib/python3.7/site-packages/notion2md/exporter.py", line 18, in block_exporter
    output.write(blocks_convertor(blocks))
  File "/home/kin/anaconda3/envs/py37/lib/python3.7/site-packages/notion2md/convertor/block.py", line 109, in blocks_convertor
    outcome_blocks = "".join([result for result in results])
  File "/home/kin/anaconda3/envs/py37/lib/python3.7/site-packages/notion2md/convertor/block.py", line 109, in <listcomp>
    outcome_blocks = "".join([result for result in results])
  File "/home/kin/anaconda3/envs/py37/lib/python3.7/concurrent/futures/_base.py", line 598, in result_iterator
    yield fs.pop().result()
  File "/home/kin/anaconda3/envs/py37/lib/python3.7/concurrent/futures/_base.py", line 428, in result
    return self.__get_result()
  File "/home/kin/anaconda3/envs/py37/lib/python3.7/concurrent/futures/_base.py", line 384, in __get_result
    raise self._exception
  File "/home/kin/anaconda3/envs/py37/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/kin/anaconda3/envs/py37/lib/python3.7/site-packages/notion2md/convertor/block.py", line 151, in block_convertor
    outcome_block += "\t"*depth + block_convertor(block,depth)
  File "/home/kin/anaconda3/envs/py37/lib/python3.7/site-packages/notion2md/convertor/block.py", line 140, in block_convertor
    outcome_block = block_type_map[block_type](information_collector(block[block_type])) + "\n\n"
  File "/home/kin/anaconda3/envs/py37/lib/python3.7/site-packages/notion2md/convertor/block.py", line 67, in image
    return f"![{information['url']}]({information['url']})\n\n{information['caption']}"
KeyError: 'url'

It seems also have other... error like URL?