gpt-researcher: Error on query: TypeError: expected string or bytes-like object, got 'NoneType'

Describe the bug Running a query results in

⚠️ Error in reading JSON, attempting to repair JSON
Error using json_repair: the JSON object must be str, bytes or bytearray, not NoneType

in the console and no output in the webUI

To Reproduce Steps to reproduce the behavior:

  1. git clone https://github.com/assafelovic/gpt-researcher.git && cd gpt-researcher
  2. python -m venv venv
  3. source venv/bin/activate
  4. pip install -r requirements.txt
  5. export OPENAI_API_KEY={sk-proj-XXX} export TAVILY_API_KEY={tvly-XXX}
  6. uvicorn main:app --reload
  7. ask for a ‘Recipe for delicious cake’ in the webUI, selecting ‘Detailed’ and ‘Informative’ options

Expected behavior A response with research

Screenshots n/a

Desktop (please complete the following information):

  • OS: EndevourOS (arch), also reproduced on MacOS without a venv
  • Python 3.12.6

Additional context Add any other context about the problem here.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 16 (1 by maintainers)

Most upvoted comments

Full traceback:

INFO:     Will watch for changes in these directories: ['/home/glaw/Github/gpt-researcher']
INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO:     Started reloader process [12339] using StatReload
/home/glaw/Github/gpt-researcher/multi_agents/agents/utils/utils.py:4: SyntaxWarning: invalid escape sequence '\ '
  """
INFO:     Started server process [12341]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     127.0.0.1:49850 - "GET / HTTP/1.1" 200 OK
INFO:     127.0.0.1:49872 - "GET /site/scripts.js HTTP/1.1" 200 OK
INFO:     127.0.0.1:49856 - "GET /static/gptr-logo.png HTTP/1.1" 200 OK
INFO:     127.0.0.1:49850 - "GET /site/styles.css HTTP/1.1" 200 OK
INFO:     127.0.0.1:49850 - "GET /static/favicon.ico HTTP/1.1" 200 OK
INFO:     ('127.0.0.1', 50934) - "WebSocket /ws" [accepted]
INFO:     connection open
INFO:     [14:43:39] 🔎 Starting the research task for 'recipe for delicious cake '...
⚠️ Error in reading JSON, attempting to repair JSON
Error using json_repair: the JSON object must be str, bytes or bytearray, not NoneType
ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/home/glaw/Github/gpt-researcher/gpt_researcher/master/actions.py", line 145, in choose_agent
    response = await create_chat_completion(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/glaw/Github/gpt-researcher/gpt_researcher/utils/llm.py", line 59, in create_chat_completion
    response = await provider.get_chat_response(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/glaw/Github/gpt-researcher/gpt_researcher/llm_provider/generic/base.py", line 96, in get_chat_response
    output = await self.llm.ainvoke(messages)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/glaw/Github/gpt-researcher/venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py", line 298, in ainvoke
    llm_result = await self.agenerate_prompt(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/glaw/Github/gpt-researcher/venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py", line 787, in agenerate_prompt
    return await self.agenerate(
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/glaw/Github/gpt-researcher/venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py", line 747, in agenerate
    raise exceptions[0]
  File "/home/glaw/Github/gpt-researcher/venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py", line 923, in _agenerate_with_cache
    result = await self._agenerate(
             ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/glaw/Github/gpt-researcher/venv/lib/python3.12/site-packages/langchain_openai/chat_models/base.py", line 843, in _agenerate
    response = await self.async_client.create(**payload)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/glaw/Github/gpt-researcher/venv/lib/python3.12/site-packages/openai/resources/chat/completions.py", line 1412, in create
    return await self._post(
           ^^^^^^^^^^^^^^^^^
  File "/home/glaw/Github/gpt-researcher/venv/lib/python3.12/site-packages/openai/_base_client.py", line 1829, in post
    return await self.request(cast_to, opts, stream=stream, stream_cls=stream_cls)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/glaw/Github/gpt-researcher/venv/lib/python3.12/site-packages/openai/_base_client.py", line 1523, in request
    return await self._request(
           ^^^^^^^^^^^^^^^^^^^^
  File "/home/glaw/Github/gpt-researcher/venv/lib/python3.12/site-packages/openai/_base_client.py", line 1624, in _request
    raise self._make_status_error_from_response(err.response) from None
openai.AuthenticationError: Error code: 401 - {'error': {'message': 'Incorrect API key provided: {sk-proj**********************************************BBj}. You can find your API key at https://platform.openai.com/account/api-keys.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_api_key'}}

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/glaw/Github/gpt-researcher/venv/lib/python3.12/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 244, in run_asgi
    result = await self.app(self.scope, self.asgi_receive, self.asgi_send)  # type: ignore[func-returns-value]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/glaw/Github/gpt-researcher/venv/lib/python3.12/site-packages/uvicorn/middleware/proxy_headers.py", line 70, in __call__
    return await self.app(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/glaw/Github/gpt-researcher/venv/lib/python3.12/site-packages/fastapi/applications.py", line 1054, in __call__
    await super().__call__(scope, receive, send)
  File "/home/glaw/Github/gpt-researcher/venv/lib/python3.12/site-packages/starlette/applications.py", line 113, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/home/glaw/Github/gpt-researcher/venv/lib/python3.12/site-packages/starlette/middleware/errors.py", line 152, in __call__
    await self.app(scope, receive, send)
  File "/home/glaw/Github/gpt-researcher/venv/lib/python3.12/site-packages/starlette/middleware/cors.py", line 77, in __call__
    await self.app(scope, receive, send)
  File "/home/glaw/Github/gpt-researcher/venv/lib/python3.12/site-packages/starlette/middleware/exceptions.py", line 62, in __call__
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
  File "/home/glaw/Github/gpt-researcher/venv/lib/python3.12/site-packages/starlette/_exception_handler.py", line 62, in wrapped_app
    raise exc
  File "/home/glaw/Github/gpt-researcher/venv/lib/python3.12/site-packages/starlette/_exception_handler.py", line 51, in wrapped_app
    await app(scope, receive, sender)
  File "/home/glaw/Github/gpt-researcher/venv/lib/python3.12/site-packages/starlette/routing.py", line 715, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/home/glaw/Github/gpt-researcher/venv/lib/python3.12/site-packages/starlette/routing.py", line 735, in app
    await route.handle(scope, receive, send)
  File "/home/glaw/Github/gpt-researcher/venv/lib/python3.12/site-packages/starlette/routing.py", line 362, in handle
    await self.app(scope, receive, send)
  File "/home/glaw/Github/gpt-researcher/venv/lib/python3.12/site-packages/starlette/routing.py", line 95, in app
    await wrap_app_handling_exceptions(app, session)(scope, receive, send)
  File "/home/glaw/Github/gpt-researcher/venv/lib/python3.12/site-packages/starlette/_exception_handler.py", line 62, in wrapped_app
    raise exc
  File "/home/glaw/Github/gpt-researcher/venv/lib/python3.12/site-packages/starlette/_exception_handler.py", line 51, in wrapped_app
    await app(scope, receive, sender)
  File "/home/glaw/Github/gpt-researcher/venv/lib/python3.12/site-packages/starlette/routing.py", line 93, in app
    await func(session)
  File "/home/glaw/Github/gpt-researcher/venv/lib/python3.12/site-packages/fastapi/routing.py", line 383, in app
    await dependant.call(**solved_result.values)
  File "/home/glaw/Github/gpt-researcher/backend/server.py", line 89, in websocket_endpoint
    report = await manager.start_streaming(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/glaw/Github/gpt-researcher/backend/websocket_manager.py", line 60, in start_streaming
    report = await run_agent(task, report_type, report_source, source_urls, tone, websocket, headers)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/glaw/Github/gpt-researcher/backend/websocket_manager.py", line 97, in run_agent
    report = await researcher.run()
             ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/glaw/Github/gpt-researcher/backend/report_type/basic_report/basic_report.py", line 41, in run
    await researcher.conduct_research()
  File "/home/glaw/Github/gpt-researcher/gpt_researcher/master/agent.py", line 116, in conduct_research
    self.agent, self.role = await choose_agent(
                            ^^^^^^^^^^^^^^^^^^^
  File "/home/glaw/Github/gpt-researcher/gpt_researcher/master/actions.py", line 162, in choose_agent
    return await handle_json_error(response)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/glaw/Github/gpt-researcher/gpt_researcher/master/actions.py", line 173, in handle_json_error
    json_string = extract_json_with_regex(response)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/glaw/Github/gpt-researcher/gpt_researcher/master/actions.py", line 189, in extract_json_with_regex
    json_match = re.search(r"{.*?}", response, re.DOTALL)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/re/__init__.py", line 177, in search
    return _compile(pattern, flags).search(string)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: expected string or bytes-like object, got 'NoneType'
INFO:     connection closed