Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

400 error when getting collection view #11

Closed
heyflorin opened this issue Mar 8, 2019 · 18 comments
Closed

400 error when getting collection view #11

heyflorin opened this issue Mar 8, 2019 · 18 comments

Comments

@heyflorin
Copy link

Tracceback is below. Quick start instructions worked fine on a page, but when trying to pick up a database/collection I get the following. Any suggestions, and thanks!

File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/site-packages/notion/client.py", line 98, in get_collection_view
    collection = self.get_block(block_id, force_refresh=force_refresh).collection
  File "/usr/local/lib/python3.7/site-packages/cached_property.py", line 35, in __get__
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "/usr/local/lib/python3.7/site-packages/notion/block.py", line 618, in collection
    self._collection = self._client.get_collection(collection_id)
  File "/usr/local/lib/python3.7/site-packages/notion/client.py", line 70, in get_collection
    return Collection(self, collection_id) if coll else None
  File "/usr/local/lib/python3.7/site-packages/notion/collection.py", line 104, in __init__
    self._client.refresh_collection_rows(self.id)
  File "/usr/local/lib/python3.7/site-packages/notion/client.py", line 115, in refresh_collection_rows
    row_ids = self.search_pages_with_parent(collection_id)
  File "/usr/local/lib/python3.7/site-packages/notion/client.py", line 172, in search_pages_with_parent
    response = self.post("searchPagesWithParent", data).json()
  File "/usr/local/lib/python3.7/site-packages/notion/client.py", line 126, in post
    raise HTTPError(response.json().get("message", "There was an error (400) submitting the request."))
requests.exceptions.HTTPError: Invalid input.

@heyflorin
Copy link
Author

Smoke Test also eventually fails:

>>> run_live_smoke_test("my_token", "https://www.notion.so/my_org/Classy-Christmas-0470b8de7f0c4abf958e69e7da1d62a9")

Created base smoke test page at: https://www.notion.so/b19699658d524e999923f38a30da81e5
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/site-packages/notion/smoke_test.py", line 54, in run_live_smoke_test
    D.move_to(C, "after")
  File "/usr/local/lib/python3.7/site-packages/notion/block.py", line 383, in move_to
    self._client.refresh_records(block=[self.id, self.get("parent_id"), target_block.id, target_block.get("parent_id")])
  File "/usr/local/lib/python3.7/site-packages/notion/client.py", line 251, in __exit__
    self.client.submit_transaction(operations)
  File "/usr/local/lib/python3.7/site-packages/notion/client.py", line 150, in submit_transaction
    self._store.run_local_operations(operations)
  File "/usr/local/lib/python3.7/site-packages/notion/store.py", line 288, in run_local_operations
    self.run_local_operation(**operation)
  File "/usr/local/lib/python3.7/site-packages/notion/store.py", line 319, in run_local_operation
    ref.insert(ref.index(args["after"]) + 1, args["id"])
ValueError: '7bbe57b2-dd5c-472b-b5cd-c8f5e4ebc275' is not in list

@wenshen35105
Copy link

It's because of the error present in the console? The error shows up when notion's database is opened.

frame.1bee5518.js:1 POST https://api-iam.intercom.io/messenger/web/events 429
Access to XMLHttpRequest at 'https://api-iam.intercom.io/messenger/web/events' from origin 'https://www.notion.so' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

@heyflorin
Copy link
Author

It's because of the error present in the console? The error shows up when notion's database is opened.

frame.1bee5518.js:1 POST https://api-iam.intercom.io/messenger/web/events 429
Access to XMLHttpRequest at 'https://api-iam.intercom.io/messenger/web/events' from origin 'https://www.notion.so' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

That looks unrelated. It's some CORS issue with intercom that existed previously.

@evertheylen
Copy link
Contributor

I am getting the same error, I'm assuming the API changed.

@pbajaria
Copy link

running into the same issue as well

@Duke-Yang
Copy link

getting same error. It worked well until three days ago.

@rampeer
Copy link

rampeer commented Mar 11, 2019

Same issue.

@heyflorin
Copy link
Author

Looking at the log, it looks like the post data structure might have changed? This is an input 400 error so it's client side. Query is set to an empty string; perhaps the API now requires a query? Or the token nomenclature could have changed. I lack the time ATM to look deeper but if someone could re-run the API calls to see if anything changed, they could use this blog post as a guide.

2019-03-11 11:22:29,445 - ERROR - Got 400 error attempting to POST to searchPagesWithParent, with data: {
  "query": "",
  "parentId": "a79f88f2-f511-4d30-9364-4d555019a9a7",
  "limit": 10000
}

@wenshen35105
Copy link

Change from "searchPagesWithParent" to "queryCollection" which requires at least JSON data "collectionId", "collectionViewId" and "loader" now. I try to send a post request to the /api/v3/queryCollection which returns a similar output as before data structure.

@wenshen35105
Copy link

wenshen35105 commented Mar 11, 2019

Change from "searchPagesWithParent" to "queryCollection" which requires at least JSON data "collectionId", "collectionViewId" and "loader" now. I try to send a post request to the /api/v3/queryCollection which returns a similar output as before data structure.

For me I simply save the "collectionViewId" into the "NotionClient" class and and hard-code the "loader" part for the "queryCollection" JSON data. Because the main goal for me is to get all the blocks inside the table and I did some modifications which works for me. Waiting for the update too!

wenshen35105@d0571c1

@evertheylen
Copy link
Contributor

My version currently has a fix. I couldn't find any example of "searchPagesWithParent" in my network logs while trying various things. In the javascript source I did find something like this: searchPagesWithParent({query:e,parentId:s.id,limit:20,spaceId:a.id}). So the only change needed was a spaceId, which you can get from client.current_space.id.

(If you view my commits, I also had a solution ready that avoided searchPagesWithParent calls entirely by replacing it with queryCollection calls. I think the current solution is cleaner.)

@evertheylen
Copy link
Contributor

My changes have been open for merging in #10 for a while now. I haven't gotten any response from @jamalex so if you need a fix quickly it may just be better to use my repo.

@pbajaria
Copy link

@evertheylen Using your repo and things are working normally again. Thanks.

@heyflorin
Copy link
Author

My version currently has a fix. I couldn't find any example of "searchPagesWithParent" in my network logs while trying various things. In the javascript source I did find something like this: searchPagesWithParent({query:e,parentId:s.id,limit:20,spaceId:a.id}). So the only change needed was a spaceId, which you can get from client.current_space.id.

(If you view my commits, I also had a solution ready that avoided searchPagesWithParent calls entirely by replacing it with queryCollection calls. I think the current solution is cleaner.)

Working great, thanks!

@heyflorin
Copy link
Author

@evertheylen Search doesn't work now, although it may never have, but it could be related. searchPagesWithParent is called when you do a "lookup" type search on a relation. Here's an example of a simple search I'm doing with the error I get.

    cvt = client.get_collection_view("https://www.notion.so/mdnt/25a979d31e6045118104bd2a6ea1355c?v=7b8ae192dc424628ab5362ba0dc02929")

    for row in cvt.collection.get_rows(search="Infographics"):
        print("We estimate the value of '{}' at {}".format(row.name, row.estimated_value))

Error:

Traceback (most recent call last):
  File "flotion.py", line 54, in <module>
    append_tags()
  File "flotion.py", line 38, in append_tags
    for row in cvt.collection.get_rows(search="Infographics"):
TypeError: get_rows() got an unexpected keyword argument 'search'

@ivanistheone
Copy link
Contributor

Note users facing this issue can temporarily use code in #10 while it is merged.

cd parent-directory-where-notion-py-is-checked-out
cd notion-py
git fetch upstream pull/10/head:marfixz
git checkout marfixz

@draav
Copy link

draav commented Apr 14, 2019

I also had this same error when trying to run this on library on a database page. +1 for the fix from @evertheylen.

For anyone using pipenv, just install using their repo instead (took me an hour to figure this out since I am just getting started with pipenv, so figured I'd share here):

pipenv install -e git+https://github.com/evertheylen/notion-py.git#egg=notion.client

@jamalex
Copy link
Owner

jamalex commented May 8, 2019

Thanks for all the great sleuthing and fixing! Sorry for the delay on my side (I'm the Executive Director of a nonprofit that's using Notion a lot, so I'm committed to keeping this library maintained, but things can get... busy). 😺

@evertheylen's lovely PR #10 was merged a couple of weeks ago and should be live on PyPI in 0.0.20 -- please re-open if you're still seeing issues. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants