Sinaptik-AI / pandas-ai

Chat with your database (SQL, CSV, pandas, polars, mongodb, noSQL, etc). PandasAI makes data analysis conversational using LLMs (GPT 3.5 / 4, Anthropic, VertexAI) and RAG.
https://pandas-ai.com
Other
12.62k stars 1.22k forks source link

Error when installing with docker #1369

Open kaziu007 opened 2 hours ago

kaziu007 commented 2 hours ago

System Info

2.2.14, macos

🐛 Describe the bug

I get following issue when installing with docker: .06 } 27.06 Get request failed TypeError: fetch failed 27.06 at Object.fetch (node:internal/deps/undici/undici:14152:11) 27.06 at process.processTicksAndRejections (node:internal/process/task_queues:95:5) 27.06 at async i (/app/build/server/app/settings/workspaces/editspaces/page.js:1:13704) 27.06 at async p (/app/build/server/app/settings/workspaces/addspaces/page.js:1:12080) { 27.06 cause: Error: connect ECONNREFUSED 127.0.0.1:8000 27.06 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1495:16) 27.06 at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) { 27.06 errno: -111, 27.06 code: 'ECONNREFUSED', 27.06 syscall: 'connect', 27.06 address: '127.0.0.1', 27.06 port: 8000 27.06 } 27.06 } 27.06 TypeError: fetch failed 27.06 at Object.fetch (node:internal/deps/undici/undici:14152:11) 27.06 at process.processTicksAndRejections (node:internal/process/task_queues:95:5) 27.06 at async i (/app/build/server/app/settings/workspaces/editspaces/page.js:1:13704) 27.06 at async p (/app/build/server/app/settings/workspaces/addspaces/page.js:1:12080) { 27.06 cause: Error: connect ECONNREFUSED 127.0.0.1:8000 27.06 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1495:16) 27.06 at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) { 27.06 errno: -111, 27.06 code: 'ECONNREFUSED', 27.06 syscall: 'connect', 27.06 address: '127.0.0.1', 27.06 port: 8000 27.06 }, 27.06 digest: '2837704541' 27.06 }

dosubot[bot] commented 2 hours ago

The error you're encountering indicates that the application is trying to connect to a service at 127.0.0.1:8000, but the connection is being refused. This typically means that the backend server is not running or not accessible at the specified address and port.

Here are a few steps to troubleshoot and resolve this issue:

  1. Ensure Backend Server is Running: Make sure that the backend server is up and running. You can check this by running:

    docker-compose up

    This command should start all the services defined in your docker-compose.yml file, including the backend server.

  2. Check Environment Variables: Verify that the environment variable NEXT_PUBLIC_API_URL is correctly set to http://localhost:8000/ in your .env files. This variable specifies the address and port for the backend service.

  3. Network Configuration: Ensure that the services are correctly connected to the same Docker network. The docker-compose.yml file should have a network configuration like this:

    networks:
     pandabi-network:
       driver: bridge

    All services should be part of this network.

  4. Logs and Errors: Check the logs for the backend server to see if there are any errors preventing it from starting. You can view the logs using:

    docker-compose logs server
  5. Port Conflicts: Ensure that port 8000 is not being used by another application on your host machine. You can check this by running:

    lsof -i :8000

By following these steps, you should be able to identify and resolve the issue preventing the connection to the backend server. If the problem persists, please provide additional details or logs for further assistance.

To continue talking to Dosu, mention @dosu.

kaziu007 commented 2 hours ago

I have NEXT_PUBLIC_API_URL='http://localhost:8000/'

still i get: 26.99 TypeError: fetch failed 26.99 at Object.fetch (node:internal/deps/undici/undici:14152:11) 26.99 at process.processTicksAndRejections (node:internal/process/task_queues:95:5) 26.99 at async n (/app/build/server/app/settings/workspaces/addspaces/page.js:1:15050) 26.99 at async u (/app/build/server/app/settings/datasets/page.js:1:8848) { 26.99 cause: Error: connect ECONNREFUSED 127.0.0.1:8000 26.99 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1495:16) 26.99 at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) { 26.99 errno: -111, 26.99 code: 'ECONNREFUSED', 26.99 syscall: 'connect', 26.99 address: '127.0.0.1', 26.99 port: 8000 26.99 }, 26.99 digest: '67092955' 26.99 }

dosubot[bot] commented 2 hours ago

Given that the NEXT_PUBLIC_API_URL is correctly set to http://localhost:8000/, the issue likely lies with the backend server not running or not being accessible. Here are some additional steps to troubleshoot:

  1. Verify Backend Server is Running: Ensure the backend server is running by executing:

    docker-compose up

    Check the logs to confirm the server has started without errors:

    docker-compose logs server
  2. Health Check Endpoint: Verify the backend server's health by accessing the health check endpoint. Open a browser or use curl to access:

    curl http://localhost:8000/health

    This endpoint should return a JSON response indicating the server's status [1].

  3. Check startup.sh Execution: Ensure the startup.sh script is executing correctly. This script is responsible for starting the server:

    #!/bin/bash
    
    # Load environment variables from .env file if it exists
    if [ -f .env ]; then
       log "Loading environment variables from .env file"
       export $(cat .env | sed 's/#.*//g' | xargs)
    else
       log ".env file not found, skipping"
    fi
    
    source $(poetry env info --path)/bin/activate
    
    poetry lock --no-update
    
    make install
    
    /bin/sh wait-for-it.sh
    
    # Run database migrations
    make migrate
    
    # Start the server in the background
    make start

    Ensure there are no errors during its execution [2].

  4. Port Conflicts: Ensure port 8000 is not being used by another application:

    lsof -i :8000
  5. Network Configuration: Confirm that all services are part of the same Docker network:

    networks:
     pandabi-network:
       driver: bridge

    All services should be connected to this network [3].

By following these steps, you should be able to identify and resolve the issue preventing the connection to the backend server. If the problem persists, please provide additional details or logs for further assistance.

To continue talking to Dosu, mention @dosu.

kaziu007 commented 1 hour ago

@dosu please name all the files in which i shall place the http://localhost. it seems so far that the setup is failing on 127.0.0.1 while i have set

6.10 } 26.10 TypeError: fetch failed 26.10 at Object.fetch (node:internal/deps/undici/undici:14152:11) 26.10 at process.processTicksAndRejections (node:internal/process/task_queues:95:5) 26.10 at async i (/app/build/server/app/settings/datasets/page.js:1:13460) 26.10 at async u (/app/build/server/app/settings/datasets/page.js:1:8848) { 26.10 cause: Error: connect ECONNREFUSED 127.0.0.1:8000 26.10 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1495:16) 26.10 at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) { 26.10 errno: -111, 26.10 code: 'ECONNREFUSED', 26.10 syscall: 'connect', 26.10 address: '127.0.0.1', 26.10 port: 8000 26.10 }, 26.10 digest: '4039937587' 26.10 }

dosubot[bot] commented 1 hour ago

To ensure the setup does not fail on 127.0.0.1, you should place the URL https://localhost in the following files:

  1. server/core/config.py: Update the POSTGRES_URL field.

    POSTGRES_URL: PostgresDsn = "postgresql+asyncpg://user:password@localhost:5432/db-name"
  2. client/.env: Set the NEXT_PUBLIC_API_URL environment variable.

    NEXT_PUBLIC_API_URL=https://localhost
  3. server/.env: Ensure any relevant environment variables point to https://localhost.

These changes should help resolve the connection issues by ensuring all services are correctly pointing to https://localhost instead of 127.0.0.1 [1][2][3].

To continue talking to Dosu, mention @dosu.

kaziu007 commented 1 hour ago

@dosu I have client/.env NEXT_PUBLIC_API_URL='http://localhost:8000/'

I have server/.env SERVER_HOST=localhost

I have server/core/config.py i have "postgresql+asyncpg://user:password@localhost:5432/db-name"

Still the error message is: 28.96 } 28.96 TypeError: fetch failed 28.96 at Object.fetch (node:internal/deps/undici/undici:14152:11) 28.96 at process.processTicksAndRejections (node:internal/process/task_queues:95:5) 28.96 at async i (/app/build/server/app/settings/workspaces/editspaces/page.js:1:13704) 28.96 at async p (/app/build/server/app/settings/workspaces/editspaces/page.js:1:12135) { 28.96 cause: Error: connect ECONNREFUSED 127.0.0.1:8000 28.96 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1495:16) 28.96 at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) { 28.96 errno: -111, 28.96 code: 'ECONNREFUSED', 28.96 syscall: 'connect', 28.96 address: '127.0.0.1', 28.96 port: 8000 28.96 }, 28.96 digest: '711901359' 28.96 }

Which other file i shall update?

kaziu007 commented 1 hour ago

@dosu I have client/.env NEXT_PUBLIC_API_URL='http://localhost:8000/'

I have server/.env SERVER_HOST=localhost

I have server/core/config.py i have "postgresql+asyncpg://user:password@localhost:5432/db-name"

Still the error message is: 28.96 } 28.96 TypeError: fetch failed 28.96 at Object.fetch (node:internal/deps/undici/undici:14152:11) 28.96 at process.processTicksAndRejections (node:internal/process/task_queues:95:5) 28.96 at async i (/app/build/server/app/settings/workspaces/editspaces/page.js:1:13704) 28.96 at async p (/app/build/server/app/settings/workspaces/editspaces/page.js:1:12135) { 28.96 cause: Error: connect ECONNREFUSED 127.0.0.1:8000 28.96 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1495:16) 28.96 at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) { 28.96 errno: -111, 28.96 code: 'ECONNREFUSED', 28.96 syscall: 'connect', 28.96 address: '127.0.0.1', 28.96 port: 8000 28.96 }, 28.96 digest: '711901359' 28.96 }

Which other file i shall update?

dosubot[bot] commented 1 hour ago

To ensure all configurations are correctly set to use http://localhost:8000, you should verify and update the following files:

  1. client/.env:

    NEXT_PUBLIC_API_URL='http://localhost:8000/'
  2. server/.env:

    SERVER_HOST=localhost
    SERVER_PORT=8000
  3. docker-compose.yml: Ensure the ports are correctly mapped and the environment variables are loaded:

    server:
     container_name: pandabi-backend
     build:
       context: ./server
       dockerfile: Dockerfile
     ports:
       - "8000:8000"
     restart: always
     env_file:
       - ./server/.env
     depends_on:
       - postgresql
     networks:
       - pandabi-network
     command: "/bin/bash startup.sh"
    
    client:
     container_name: pandabi-frontend
     build:
       context: ./client
       dockerfile: Dockerfile
     ports:
       - "3000:3000"
     restart: always
     env_file:
       - ./client/.env
     environment:
       - NODE_ENV=development
     command: npm run start
     networks:
       - pandabi-network
  4. server/main.py: Ensure the server is set to use the environment variables:

    import os
    
    if __name__ == "__main__":
       import uvicorn
       uvicorn.run(
           "app.main:app",
           host=os.environ.get("SERVER_HOST", "0.0.0.0"),
           port=int(os.environ.get("SERVER_PORT", 8000)),
           reload=True
       )
  5. server/startup.sh: Ensure the script loads the environment variables correctly:

    #!/bin/bash
    
    # Load environment variables from .env file if it exists
    if [ -f .env ]; then
       log "Loading environment variables from .env file"
       export $(cat .env | sed 's/#.*//g' | xargs)
    else
       log ".env file not found, skipping"
    fi
    
    source $(poetry env info --path)/bin/activate
    
    poetry lock --no-update
    
    make install
    
    /bin/sh wait-for-it.sh
    
    # Run database migrations
    make migrate
    
    # Start the server in the background
    make start

By ensuring these configurations are correctly set, you should be able to resolve the connection issue to http://localhost:8000 [1][2][3].

To continue talking to Dosu, mention @dosu.

kaziu007 commented 32 minutes ago

@dosu It looks like the backend is not starting up. I check all the files and it is correct. Shall i update the 127.0.0.1 to local host in all occurences?

dosubot[bot] commented 30 minutes ago

Updating all occurrences of 127.0.0.1 to localhost is not necessary to ensure the backend starts up correctly. Both 127.0.0.1 and localhost refer to the local machine and should work interchangeably for local development. The configuration using 127.0.0.1 is valid and should work correctly [1].

If the backend is not starting up, you should check the following:

  1. Logs and Errors: Check the logs for any errors that might indicate why the backend is not starting. You can view the logs using:

    docker-compose logs server
  2. Health Check Endpoint: Verify the backend server's health by accessing the health check endpoint:

    curl http://localhost:8000/health

    This endpoint should return a JSON response indicating the server's status [2].

  3. Error Handling Mechanisms: Ensure that the error handling mechanisms in place are not indicating any issues. The on_auth_error and custom_exception_handler functions provide detailed error messages that can help diagnose the problem [3].

  4. Startup Script Execution: Ensure the startup.sh script is executing correctly without errors. This script is responsible for starting the server [4].

By following these steps, you should be able to identify and resolve the issue preventing the backend from starting.

To continue talking to Dosu, mention @dosu.

kaziu007 commented 29 minutes ago

@dosu docker-compose logs server is not returning anything

curl http://localhost:8000/health is not found.

The backend cannot start. script.sh runs without errors

dosubot[bot] commented 28 minutes ago

If docker-compose logs server is not returning anything and curl http://localhost:8000/health is not found, it indicates that the backend server is not starting at all. Here are some steps to further diagnose and resolve the issue:

  1. Check Docker Compose Configuration: Ensure that the docker-compose.yml file is correctly configured to build and start the backend server. The relevant section should look like this:

    server:
     container_name: pandabi-backend
     build:
       context: ./server
       dockerfile: Dockerfile
     ports:
       - "8000:8000"
     restart: always
     env_file:
       - ./server/.env
     depends_on:
       - postgresql
     networks:
       - pandabi-network
     command: "/bin/bash startup.sh"

    Make sure the paths and filenames are correct [1].

  2. Verify Dockerfile: Ensure the server/Dockerfile is correctly set up to build the backend server. The Dockerfile should include all necessary dependencies and commands to start the server:

    FROM python:3.11-slim
    
    WORKDIR /app
    
    RUN apt-get update && apt-get install -y --no-install-recommends \
       build-essential \
       curl \
       make \
       && apt-get clean \
       && rm -rf /var/lib/apt/lists/*
    
    RUN curl -sSL https://install.python-poetry.org | python3 -
    
    RUN apt-get update && apt-get install netcat-openbsd -y
    
    ENV PATH="/root/.local/bin:$PATH"
    
    COPY . /app
    
    RUN poetry lock --no-update
    
    RUN poetry install --no-root
    
    COPY wait-for-it.sh /wait-for-it.sh
    RUN chmod +x /wait-for-it.sh
    
    EXPOSE 8000
    
    COPY startup.sh /startup.sh
    RUN chmod +x /startup.sh
    
    CMD ["/startup.sh"]

    Ensure there are no errors during the build process [2].

  3. Check startup.sh Execution: Ensure the startup.sh script is correctly starting the server. The script should look like this:

    #!/bin/bash
    
    # Load environment variables from .env file if it exists
    if [ -f .env ]; then
       log "Loading environment variables from .env file"
       export $(cat .env | sed 's/#.*//g' | xargs)
    else
       log ".env file not found, skipping"
    fi
    
    source $(poetry env info --path)/bin/activate
    
    poetry lock --no-update
    
    make install
    
    /bin/sh wait-for-it.sh
    
    # Run database migrations
    make migrate
    
    # Start the server in the background
    make start

    Ensure there are no errors during its execution [3].

  4. Check Environment Variables: Ensure all required environment variables are correctly set in server/.env:

    POSTGRES_URL=postgresql+asyncpg://pandasai:password123@postgresql:5432/pandasai-db
    TEST_POSTGRES_URL=postgresql+asyncpg://pandasai:password123@postgresql:5432/pandasai-db
    PANDASAI_API_KEY=your_pandasai_api_key_here
    # OPENAI_API_KEY=your_openai_api_key_here (use only if you want to use OpenAI instead of PANDASAI_API_KEY)
    
    ENVIRONMENT=development
    DEBUG=1
    SHOW_SQL_ALCHEMY_QUERIES=0
    SERVER_HOST=localhost
    SERVER_PORT=8000

    Ensure these variables are correctly loaded [4].

  5. Manually Start the Server: Try manually starting the server inside the Docker container to see if there are any errors:

    docker-compose run server /bin/bash
    # Inside the container
    python main.py

    This can help identify any issues that occur during the server startup.

By following these steps, you should be able to identify and resolve the issue preventing the backend server from starting.

To continue talking to Dosu, mention @dosu.

kaziu007 commented 26 minutes ago

@dosu

I have following message: raceback (most recent call last): File "/app/main.py", line 2, in import uvicorn ModuleNotFoundError: No module named 'uvicorn'

dosubot[bot] commented 24 minutes ago

The error ModuleNotFoundError: No module named 'uvicorn' indicates that the uvicorn package is not installed in your environment. Here are the steps to resolve this issue:

  1. Ensure uvicorn is listed in pyproject.toml: Verify that uvicorn is included as a dependency in your pyproject.toml file:

    [tool.poetry.dependencies]
    uvicorn = "^0.20.0"
  2. Install Dependencies: Ensure all dependencies are installed by running the following command inside the server directory:

    poetry install
  3. Rebuild Docker Image: Rebuild the Docker image to ensure all dependencies are included:

    docker-compose build
  4. Start Docker Containers: Start the Docker containers again:

    docker-compose up

By following these steps, uvicorn should be installed, and the backend server should start without the ModuleNotFoundError [1].

To continue talking to Dosu, mention @dosu.