I am currently trying to informally connect to the Notion homepage to upload an image. The reason for using informal API is that it does not allow us to upload images from our local folders.
With that said, I successfully connected to my homepage using token_v2 and created an image block using children.add_new('image'). However, when I tried to upload an image, I ran across 403 Client Error.
I've been trying to solve this issue for a few days so please let me know if there's anything I'm missing. Below is my code.
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()
Error Code
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