小编And*_*Lee的帖子

Notion APi HTTPError:403 客户端错误:禁止 url:https://www.notion.so/api/v3/getUploadFileUrl

我目前正在尝试非正式地连接到 Notion 主页来上传图像。使用非正式 API 的原因是它不允许我们从本地文件夹上传图像。

话虽如此,我使用 token_v2 成功连接到我的主页,并使用Children.add_new('image')创建了一个图像块。然而,当我尝试上传图像时,遇到了 403 客户端错误。

几天来我一直在努力解决这个问题,所以如果我遗漏了什么,请告诉我。下面是我的代码。

from notion.client import NotionClient

def uploadEvaluationJPG():
    token_v2 = secret.notion_API("token_v2")
    client = NotionClient(token_v2=token_v2)
    # connect page
    url = 'https://www.notion.so/Home-******************************'
    page = client.get_block(url)
            
    newchild = page.children.add_new('image')
    newchild.upload_file(r"C:\NotionUpdate\progress\jpg files\Monthly Evaluation\month.jpg")
    newchild.move_to(page.children[1],"before")
    page.children[0].remove()  
Run Code Online (Sandbox Code Playgroud)

错误代码

Traceback (most recent call last):

  Input In [8] in <cell line: 11>
    newchild.upload_file(r"C:\NotionUpdate\progress\jpg files\Monthly Evaluation\month.jpg")

  File ~\AppData\Roaming\Python\Python39\site-packages\notion\block.py:641 in upload_file
    data = self._client.post(

  File ~\AppData\Roaming\Python\Python39\site-packages\notion\client.py:265 in post
    response.raise_for_status()

  File ~\AppData\Roaming\Python\Python39\site-packages\requests\models.py:909 in raise_for_status
    raise HTTPError(http_error_msg, response=self)

HTTPError: 403 Client …
Run Code Online (Sandbox Code Playgroud)

python file-upload http-error notion-api

2
推荐指数
1
解决办法
1073
查看次数

标签 统计

file-upload ×1

http-error ×1

notion-api ×1

python ×1