HTTPError when retrieving Notion page title through Python API

I’m working with the notion.py library as a beginner in Python and I’m facing difficulties when trying to retrieve titles from Notion pages. I want to get the title from one page and display it on another page, but I keep running into an HTTPError stating “Invalid input”.

Here’s the error message I’m seeing:

Traceback (most recent call last):
  File "notion_page_reader.py", line 12, in <module>
    source_page = notion_client.get_block(source_page_url)
  File "/usr/local/lib/python3.6/site-packages/notion/client.py", line 169, in get_block
    block = self.get_record_data("block", block_id, force_refresh=force_refresh)
  File "/usr/local/lib/python3.6/site-packages/notion/client.py", line 162, in get_record_data
    return self._store.get(table, id, force_refresh=force_refresh)
  File "/usr/local/lib/python3.6/site-packages/notion/store.py", line 184, in get
    self.call_load_page_chunk(id)
  File "/usr/local/lib/python3.6/site-packages/notion/store.py", line 286, in call_load_page_chunk
    recordmap = self._client.post("loadPageChunk", data).json()["recordMap"]
  File "/usr/local/lib/python3.6/site-packages/notion/client.py", line 262, in post
    "message", "There was an error (400) submitting the request."
requests.exceptions.HTTPError: Invalid input.

This is the code I’m using:

from notion.client import NotionClient
import time

auth_token = "my_authentication_token"
notion_client = NotionClient(token_v2=auth_token)

source_page_url = 'url_of_source_page'
source_page = notion_client.get_block(source_page_url)

destination_page_url = 'url_of_destination_page'
destination_page = notion_client.get_block(destination_page_url)

print(source_page.title)

What could be the reason for this 400 error, and how can I effectively retrieve page titles?

ya, that’s a common prob when working with notion.py. check if ur auth token is still valid, sometimes they expire or get messed up. regeneratin it from browser cookies often helps! also, double-check the page urls for access rights.

The notion.py library is deprecated and no longer maintained, which explains why you’re encountering these HTTP errors. The library relies on unofficial API endpoints that Notion has changed or restricted access to over time. I encountered similar issues last year when trying to use notion.py for a project and found that switching to the official Notion API solved all my problems. You’ll need to create an integration through Notion’s developer portal, get a proper API key, and use the official notion-client library instead. The syntax is different but much more reliable. Make sure to share your pages with the integration after creating it, otherwise you’ll get permission errors even with valid credentials.

Had this exact same issue a few months back when I was trying to build a simple page aggregator. The problem is likely that you’re passing the full URL to get_block() instead of extracting the page ID. The notion.py library expects just the UUID part of the URL, not the entire thing. Try extracting the 32-character ID from your URL - it’s usually the last part after the final slash. Also worth noting that if the page is in a workspace where your token doesn’t have proper access permissions, you’ll get cryptic error messages like this. I ended up having to verify my token had access to the specific workspace containing those pages.