jamalex / notion-py

Unofficial Python API client for Notion.so
MIT License
4.3k stars 475 forks source link

requests.exceptions.HTTPError: Invalid input from client.get_block #382

Closed williamium3000 closed 1 year ago

williamium3000 commented 1 year ago

I get the requests.exceptions.HTTPError: Invalid problem when calling client.get_block() I don't get a solution from previous issues. What do you think is the best practice now or how can I fix this?

from notion.client import NotionClient
from notion.block import PageBlock
client = NotionClient(token_v2="xxx")
page = client.get_block("https://www.notion.so/xxx-xxx")
yffenim commented 1 year ago

I am getting the exact same issue. All I did was replace the values for token_v2 and the page url with my own exactly as shown in readme.

from notion.client import NotionClient

notion_token_from_header = 'the v2token'
notion_page = 'https://www.notion.so/___/___'

client = NotionClient(token_v2=notion_token_from_header)
print(client) # this part is working

page = client.get_block(notion_page) # this gives error

The error msg:

Traceback (most recent call last):
  File "/Users/emin/Development/for_pamela/notion/script.py", line 75, in <module>
    page = client.get_block(url)
  File "/Users/emin/Development/for_pamela/notion/virtualenv/lib/python3.10/site-packages/notion/client.py", line 169, in get_block
    block = self.get_record_data("block", block_id, force_refresh=force_refresh)
  File "/Users/emin/Development/for_pamela/notion/virtualenv/lib/python3.10/site-packages/notion/client.py", line 162, in get_record_data
    return self._store.get(table, id, force_refresh=force_refresh)
  File "/Users/emin/Development/for_pamela/notion/virtualenv/lib/python3.10/site-packages/notion/store.py", line 184, in get
    self.call_load_page_chunk(id)
  File "/Users/emin/Development/for_pamela/notion/virtualenv/lib/python3.10/site-packages/notion/store.py", line 286, in call_load_page_chunk
    recordmap = self._client.post("loadPageChunk", data).json()["recordMap"]
  File "/Users/emin/Development/for_pamela/notion/virtualenv/lib/python3.10/site-packages/notion/client.py", line 260, in post
    raise HTTPError(
requests.exceptions.HTTPError: Invalid input.

I've ensured that I'm logged in my browser, using token_v2 request cookie from loading the intended page request, and the permissions on the page are private.

Can you address this? Otherwise such a waste of a beautiful sdk.

tyePhDCandy commented 1 year ago

I am getting the exact same issue. All I did was replace the values for token_v2 and the page url with my own exactly as shown in readme. I highly doubt that it's a proxy problem, since we all come from mainland, china. This issue can not be solved by using vpn, it can only be solved by setting proxy server into parameters of certain functions.

bishalnepali commented 1 year ago

Also getting the same issues :(

egeres commented 1 year ago

Is it possible this issue is fixed in this fork? https://github.com/vzhd1701/notion-py

mhsong55 commented 1 year ago

I had the same issue and solved it. The cause was in the cookie value (token_v2). I cleared the cookie value in the web browser and refreshed the browser. After that, I proceeded based on the newly received cookie value, and it worked normally.

tyePhDCandy commented 1 year ago

I have already switched to notion-sdk-py and notional. They are both very active repositories.

williamium3000 commented 1 year ago

vpn is not the issue, I am currently US still not working

williamium3000 commented 1 year ago

Hi all, the issue is solved by https://github.com/vzhd1701/notion-py as stated by @egeres . Thanks The problem is that the 0.0.36 is not updated to pip, thus directly using pip cannot install the newest version. My approach is to download from GitHub the source code from https://github.com/vzhd1701/notion-py and install through pip install .