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

[Bug]: 401 Client Error: Unauthorized for url: https://api.notion.com/v1/search #2396

Open
wangshuai-wuhan opened this issue Apr 1, 2024 · 1 comment
Labels
area: backend Related to backend functionality or under the /backend directory bug Something isn't working

Comments

@wangshuai-wuhan
Copy link

What happened?

@StanGirard the quivr can answer a question from source now. but waiting a minitue, docker apper an 401 Client Error: Unauthorized for url: https://api.notion.com/v1/search。Will this be a problem for next question , like repeating cousume huge tokens. it‘ takes big price to use gpt 4。

i put quivr on wsl in window 11 and have to ues a vpn proxy fro opneai api . being not a porgramer ,i feel At a loss to meet those errors during many trials, i would like to subscribe your quivr app , but it still appear network Error. I am on the edge of giving up.

Relevant log output

2024-04-01 08:24:46 backend-core  | INFO:     127.0.0.1:41986 - "GET /healthz HTTP/1.1" 200 OK
2024-04-01 08:25:00 beat          | [2024-04-01 00:25:00,012: INFO/MainProcess] Scheduler: Sending due task process_integration_brain_sync (celery_worker.process_integration_brain_sync)
2024-04-01 08:25:00 worker        | [2024-04-01 00:25:00,017: INFO/MainProcess] Task celery_worker.process_integration_brain_sync[ba778222-2d0e-416e-8c08-cf717dddb2e9] received
2024-04-01 08:25:00 worker        | [2024-04-01 00:25:00,055: INFO/ForkPoolWorker-2] HTTP Request: GET http://host.docker.internal:54321/rest/v1/integrations_user?select=%2A%2C%20integrations%20%28%29&integrations.integration_name=eq.notion "HTTP/1.1 200 OK"
2024-04-01 08:25:00 worker        | [2024-04-01 00:25:00,055: WARNING/ForkPoolWorker-2] last_synced: 2024-03-21T16:39:09.515934+00:00
2024-04-01 08:25:00 worker        | [2024-04-01 00:25:00,059: INFO/MainProcess] Task celery_worker.process_integration_brain_sync_user_brain[2b0f7397-3bee-49eb-8af1-877f9f564bd6] received
2024-04-01 08:25:00 worker        | [2024-04-01 00:25:00,059: INFO/ForkPoolWorker-2] Task celery_worker.process_integration_brain_sync[ba778222-2d0e-416e-8c08-cf717dddb2e9] succeeded in 0.04005819000303745s: None
2024-04-01 08:25:00 worker        | [2024-04-01 00:25:00,088: INFO/ForkPoolWorker-2] HTTP Request: GET http://host.docker.internal:54321/rest/v1/integrations_user?select=%2A&brain_id=eq.b5d71873-d010-498f-aa6e-a47fe897b197 "HTTP/1.1 200 OK"
2024-04-01 08:25:00 worker        | [INFO] modules.brain.integrations.Notion.Notion_connector [Notion_connector.py:65]: Loading Notion credentials
2024-04-01 08:25:00 worker        | [2024-04-01 00:25:00,099: INFO/ForkPoolWorker-2] HTTP Request: PATCH http://host.docker.internal:54321/rest/v1/integrations_user?brain_id=eq.b5d71873-d010-498f-aa6e-a47fe897b197&user_id=eq.39418e3b-0258-4452-af60-7acfcc1263ff "HTTP/1.1 200 OK"
2024-04-01 08:25:00 worker        | [2024-04-01 00:25:00,116: INFO/ForkPoolWorker-2] HTTP Request: GET http://host.docker.internal:54321/rest/v1/integrations_user?select=%2A&brain_id=eq.b5d71873-d010-498f-aa6e-a47fe897b197 "HTTP/1.1 200 OK"
2024-04-01 08:25:00 worker        | [2024-04-01 00:25:00,885: ERROR/ForkPoolWorker-2] Task celery_worker.process_integration_brain_sync_user_brain[2b0f7397-3bee-49eb-8af1-877f9f564bd6] raised unexpected: HTTPError('401 Client Error: Unauthorized for url: https://api.notion.com/v1/search')
2024-04-01 08:25:00 worker        | Traceback (most recent call last):
2024-04-01 08:25:00 worker        |   File "/usr/local/lib/python3.11/site-packages/celery/app/trace.py", line 477, in trace_task
2024-04-01 08:25:00 worker        |     R = retval = fun(*args, **kwargs)
2024-04-01 08:25:00 worker        |                  ^^^^^^^^^^^^^^^^^^^^
2024-04-01 08:25:00 worker        |   File "/usr/local/lib/python3.11/site-packages/celery/app/trace.py", line 760, in __protected_call__
2024-04-01 08:25:00 worker        |     return self.run(*args, **kwargs)
2024-04-01 08:25:00 worker        |            ^^^^^^^^^^^^^^^^^^^^^^^^^
2024-04-01 08:25:00 worker        |   File "/code/celery_worker.py", line 181, in process_integration_brain_sync_user_brain
2024-04-01 08:25:00 worker        |     notion_connector.poll()
2024-04-01 08:25:00 worker        |   File "/code/modules/brain/integrations/Notion/Notion_connector.py", line 357, in poll
2024-04-01 08:25:00 worker        |     db_res = self._search_notion(query_dict)
2024-04-01 08:25:00 worker        |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-04-01 08:25:00 worker        |   File "/code/modules/brain/integrations/Notion/Notion_connector.py", line 99, in _search_notion
2024-04-01 08:25:00 worker        |     res.raise_for_status()
2024-04-01 08:25:00 worker        |   File "/usr/local/lib/python3.11/site-packages/requests/models.py", line 1021, in raise_for_status
2024-04-01 08:25:00 worker        |     raise HTTPError(http_error_msg, response=self)
2024-04-01 08:25:00 worker        | requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://api.notion.com/v1/search
2024-04-01 08:25:16 backend-core  | INFO:     127.0.0.1:51044 - "GET /healthz HTTP/1.1" 200 OK
2024-04-01 08:25:46 backend-core  | INFO:     127.0.0.1:35818 - "GET /healthz HTTP/1.1" 200 OK
2024-04-01 08:26:17 backend-core  | INFO:     127.0.0.1:34556 - "GET /healthz HTTP/1.1" 200 OK

Twitter / LinkedIn details

No response

@wangshuai-wuhan wangshuai-wuhan added the bug Something isn't working label Apr 1, 2024
Copy link

dosubot bot commented Apr 1, 2024

Hey there, @wangshuai-wuhan! Nice to see you back with us. Hope you're doing well amidst these tech hiccups!

Based on the error logs you've provided, it seems like the issue is related to the Notion API authentication. The "401 Client Error: Unauthorized" error typically occurs when the API token (also known as the integration token) is missing, incorrect, or has been revoked, leading to unauthorized access attempts to the Notion API.

To resolve this issue, you can follow these steps:

  1. Verify the Integration Token: Ensure that the notion_integration_token you've provided in your integration details is correct. This token should be the one generated when you created the integration on Notion's side. You can find or regenerate this token in your Notion integration settings.

  2. Update the Token in Your Application: If the token has been updated or was incorrect, make sure to update it in the place where your application stores or retrieves the Notion credentials. In the provided code, this would involve ensuring that the correct token is set in the self.integration_details.settings dictionary under the key "notion_integration_token".

  3. Check Token Permissions: Ensure that the integration token has the necessary permissions to access the resources you're trying to access with the API. This includes permissions to read or write pages, depending on what your application is doing.

  4. Review API Version: The code specifies the Notion API version as "Notion-Version": "2022-06-28". Ensure that this version is still supported and hasn't been deprecated. If a new version is available, consider updating to it after reviewing any potential changes that could affect your application.

Here's the relevant part of your code that sets up the authorization header, which is where you should ensure the correct token is being used:

def _headers(self) -> dict[str, str]:
    """Get the headers for the Notion API"""
    return {
        "Authorization": f'Bearer {self.credentials["notion_integration_token"]}',
        "Content-Type": "application/json",
        "Notion-Version": "2022-06-28",
    }

Ensure that self.credentials["notion_integration_token"] contains the correct and valid token. If you've verified the token and are still encountering issues, you may need to regenerate the token from the Notion integration settings and update your application accordingly.

For more details, you can refer to the NotionConnector class in the quivr repository.

I hope this helps! If you have any other questions or need further clarification, feel free to ask.

Sources

About Dosu

This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

@dosubot dosubot bot added the area: backend Related to backend functionality or under the /backend directory label Apr 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: backend Related to backend functionality or under the /backend directory bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant