我目前正试图非正式地连接到概念主页上传图片。使用非正式API的原因是它不允许我们从本地文件夹上传图像。
尽管如此,我成功地使用children.add_new('image').连接到我的主页,并使用token_v2创建了一个图像块。然而,当我试图上传一个图像时,我遇到了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()
错误码
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 Error: Forbidden for url: https://www.notion.so/api/v3/getUploadFileUrl
发布于 2022-06-10 10:05:09
代码是正确的,看起来Cloudflare在请求到达概念之前就阻止了它们。
如果我们使用云代理在Postman中运行请求,我们将获得一个成功的响应200。选择桌面代理,虽然,我们得到403禁止消息。此外,我们也可以预览其原因。上面写着:
请注意,我们正在检查你的浏览器.
因此,似乎概念/Cloudflare不喜欢请求的起源。
概念现在有一个官方API,但遗憾的是,文件上传还没有实现,我们将不得不等待它。如果加强安全性,许多其他东西可能会在非官方API中失败。
在邮递员中复制:
网址:https://www.notion.so/api/v3/getUploadFileUrl
身体:
{"bucket":"secure","name":"envs.toml","contentType":"text/plain; charset=utf-8"}
对于身份验证,使用值token_v2=your_token
创建一个名为cookie的标头
https://stackoverflow.com/questions/72502604
复制相似问题