如何在 notion-py(Notion API) 中填充 'multi-select' 类型的列?

How to fill a column of type 'multi-select' in notion-py(Notion API)?

我正在尝试创建一个电报机器人,它将在概念中创建笔记,为此我使用:

然后我通过添加token_v2连接我的概念,然后接收关于我想保存在概念中的笔记的数据,最后我在概念上保存了一个笔记这样的:

    def make_notion_row():
        collection_view = client.get_collection_view(list_url[temporary_category]) #take collection
        print(temporary_category)
        print(temporary_name)
        print(temporary_link)
        print(temporary_subcategory)
        print(temporary_tag)
        row = collection_view.collection.add_row() #make row
        row.ssylka = temporary_link #this is link
        row.nazvanie_zametki = temporary_name #this is name
        if temporary_category == 0: #this is category, where do I want to save the note
            row.stil = temporary_subcategory #this is subcategory
            tags = temporary_tag.split(',') #temporary_tags is text that has many tags separated by commas. I want to get these tags as an array
            for tag_one in tags:
                **add_new_multi_select_value("Теги", tag_one): #"Теги" is "Tag column" in russian. in this situation, tag_one takes on the following values: ['my_hero_academia','midoria']**
        else:
            row.kategoria = temporary_subcategory

此脚本有效,但问题是填写类型为 multi-select.

Tags

由于在自述文件'notion-py'中没有提到填写'multi-select',因此

我用了bkiac function:https://github.com/jamalex/notion-py/issues/51

这里是我稍微修改过的函数:

    art_tags = ['ryuko_matoi', 'kill_la_kill']
    def add_new_multi_select_value(prop, value, style=None):
       ​global temporary_prop_schema
       ​if style is None:
           ​style = choice(art_tags)

       ​collection_schema = collection_view.collection.get(["schema"])
       ​prop_schema = next(
           ​(v for k, v in collection_schema.items() if v["name"] == prop), None
       ​)
       ​if not prop_schema:
           ​raise ValueError(
               ​f'"{prop}" property does not exist on the collection!'
           ​)
       ​if prop_schema["type"] != "multi_select":
           ​raise ValueError(f'"{prop}" is not a multi select property!')

       ​dupe = next(
           ​(o for o in prop_schema["options"] if o["value"] == value), None
       ​)
       ​if dupe:
           ​raise ValueError(f'"{value}" already exists in the schema!')
       ​temporary_prop_schema = prop_schema
       ​prop_schema["options"].append(
           ​{"id": str(uuid1()), "value": value, "style": style}
       ​)
       ​collection.set("schema", collection_schema)`

但是发现这个函数不起作用,报如下错误:

    add_new_multi_select_value("Теги","my_hero_academia)
    Traceback (most recent call last):
     ​File "<pyshell#4>", line 1, in <module>
       ​add_new_multi_select_value("Теги","my_hero_academia)
     ​File "C:\Users\laere\OneDrive\Documents\Programming\Other\notion-bot\program\notionbot\test.py", line 53, in add_new_multi_select_value
       ​collection.set("schema", collection_schema)
     ​File "C:\Users\laere\AppData\Local\Programs\Python\Python39-32\lib\site-packages\notion\records.py", line 115, in set
       ​self._client.submit_transaction(
     ​File "C:\Users\laere\AppData\Local\Programs\Python\Python39-32\lib\site-packages\notion\client.py", line 290, in submit_transaction
       ​self.post("submitTransaction", data)
     ​File "C:\Users\laere\AppData\Local\Programs\Python\Python39-32\lib\site-packages\notion\client.py", line 260, in post
       ​raise HTTPError(
    requests.exceptions.HTTPError: Unsaved transactions: Not allowed to edit column: schema

这是我的 table 图片:link 这是我与机器人聊天的电报:link

老实说,我不知道如何解决这个问题,问题是如何填充'multi-select'类型的列?

我用这个命令解决了这个问题

row.set_property("Категория", temporary_subcategory)

如果出现“选项...”错误,请不要害怕,这可以通过为 'multi-select' 字段添加设置来解决。