Local source code startup cannot start API service #8801

Closed
opened 2026-02-21 18:27:45 -05:00 by yindo · 3 comments
Owner

Originally created by @a-l-o-n-g on GitHub (Mar 1, 2025).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.15.3

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

Deploying dify using local source code startup, but executing Flask run - host 0.0.0.0- port=5001- debug did not return the correct output. What is the reason for this?
Image

✔️ Expected Behavior

No response

Actual Behavior

No response

Originally created by @a-l-o-n-g on GitHub (Mar 1, 2025). ### Self Checks - [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [x] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version 0.15.3 ### Cloud or Self Hosted Self Hosted (Source) ### Steps to reproduce Deploying dify using local source code startup, but executing Flask run - host 0.0.0.0- port=5001- debug did not return the correct output. What is the reason for this? ![Image](https://github.com/user-attachments/assets/da5bf669-376a-454e-a610-834798798c6d) ### ✔️ Expected Behavior _No response_ ### ❌ Actual Behavior _No response_
yindo added the 🤔 cant-reproduce label 2026-02-21 18:27:45 -05:00
yindo closed this issue 2026-02-21 18:27:45 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Mar 1, 2025):

Hey @a-l-o-n-g! 👋 I'm here to help you with any bugs, questions, or contributions you have for Dify. I'm like a helpful bot sidekick while you wait for a human maintainer.

I found a similar closed issue that might help. The suggested solution for ERR_CONNECTION_REFUSED errors when starting the API service is to ensure the API server is running and listening on the correct address and port. You should start the API server with the following command:

flask run --host 0.0.0.0 --port=5001 --debug

This command ensures that the server listens on all available network interfaces (0.0.0.0), which is necessary if you are accessing the server from a different machine or a containerized environment. Additionally, make sure that the necessary middleware services like PostgreSQL, Redis, and Weaviate are set up using Docker Compose. You can start these services with:

cd docker
cp middleware.env.example middleware.env
docker compose -f docker-compose.middleware.yaml up -d

Ensure that there are no firewall rules blocking the connection to port 5001, and verify that the Python environment is correctly set up with Python 3.12 and all dependencies are installed using Poetry [1].

If the issue persists, you might want to check the logging and debugging information available when starting the Dify API service. Adjusting the LOG_LEVEL to DEBUG and ensuring FLASK_DEBUG is enabled can provide more detailed logs that might help diagnose the issue [2].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

@dosubot[bot] commented on GitHub (Mar 1, 2025): <!-- Greeting --> Hey @a-l-o-n-g! 👋 I'm here to help you with any bugs, questions, or contributions you have for Dify. I'm like a helpful bot sidekick while you wait for a human maintainer. <!-- Answer --> I found a similar closed issue that might help. The suggested solution for `ERR_CONNECTION_REFUSED` errors when starting the API service is to ensure the API server is running and listening on the correct address and port. You should start the API server with the following command: ```bash flask run --host 0.0.0.0 --port=5001 --debug ``` This command ensures that the server listens on all available network interfaces (`0.0.0.0`), which is necessary if you are accessing the server from a different machine or a containerized environment. Additionally, make sure that the necessary middleware services like PostgreSQL, Redis, and Weaviate are set up using Docker Compose. You can start these services with: ```bash cd docker cp middleware.env.example middleware.env docker compose -f docker-compose.middleware.yaml up -d ``` Ensure that there are no firewall rules blocking the connection to port 5001, and verify that the Python environment is correctly set up with Python 3.12 and all dependencies are installed using Poetry <sup>[[1]](https://github.com/langgenius/dify/issues/13806)</sup>. If the issue persists, you might want to check the logging and debugging information available when starting the Dify API service. Adjusting the `LOG_LEVEL` to `DEBUG` and ensuring `FLASK_DEBUG` is enabled can provide more detailed logs that might help diagnose the issue <sup>[[2]](https://github.com/langgenius/dify/blob/main/docker/docker-compose.yaml)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.* --- <sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/68c67902-7c7e-41b1-9850-d4e3da670d5c?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/68c67902-7c7e-41b1-9850-d4e3da670d5c?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/68c67902-7c7e-41b1-9850-d4e3da670d5c?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/68c67902-7c7e-41b1-9850-d4e3da670d5c?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/68c67902-7c7e-41b1-9850-d4e3da670d5c?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/68c67902-7c7e-41b1-9850-d4e3da670d5c?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/68c67902-7c7e-41b1-9850-d4e3da670d5c?feedback_type=other)</sup>
Author
Owner

@a-l-o-n-g commented on GitHub (Mar 1, 2025):

I followed the correct execution steps, but I still couldn't start the API service and the project still displayed net:: ERR_CONNECTION_REFUSED,
@crazywoola @dosu
Image

@a-l-o-n-g commented on GitHub (Mar 1, 2025): I followed the correct execution steps, but I still couldn't start the API service and the project still displayed net:: ERR_CONNECTION_REFUSED, @crazywoola @dosu ![Image](https://github.com/user-attachments/assets/678dcd5a-6ca9-4b8e-ab57-f057ebe8aee6)
Author
Owner

@dosubot[bot] commented on GitHub (Mar 1, 2025):

To resolve the net::ERR_CONNECTION_REFUSED and TypeError: Failed to fetch errors, ensure that your API URLs are correctly configured in the .env file. Check the following environment variables:

  • CONSOLE_API_URL
  • SERVICE_API_URL
  • APP_API_URL

Verify that your docker-compose.yaml file is correctly set up, and ensure the api service is properly configured with the necessary environment variables. Make sure the api service is running and accessible on the expected ports. If using Docker, ensure the necessary ports are exposed and mapped correctly. You might need to uncomment and configure the ports section for the api service:

# uncomment to expose dify-api port to host
# ports:
#   - "5001:5001"

Additionally, start the API server with the correct host and port configuration using:

flask run --host 0.0.0.0 --port=5001 --debug

Ensure middleware services are running by executing:

cd docker
cp middleware.env.example middleware.env
docker compose -f docker-compose.middleware.yaml up -d

Check that no firewall rules are blocking port 5001, and verify that the Python environment is correctly set up with Python 3.12 and all dependencies are installed using Poetry [1][2].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

@dosubot[bot] commented on GitHub (Mar 1, 2025): <!-- Answer --> To resolve the `net::ERR_CONNECTION_REFUSED` and `TypeError: Failed to fetch` errors, ensure that your API URLs are correctly configured in the `.env` file. Check the following environment variables: - `CONSOLE_API_URL` - `SERVICE_API_URL` - `APP_API_URL` Verify that your `docker-compose.yaml` file is correctly set up, and ensure the `api` service is properly configured with the necessary environment variables. Make sure the `api` service is running and accessible on the expected ports. If using Docker, ensure the necessary ports are exposed and mapped correctly. You might need to uncomment and configure the ports section for the `api` service: ```yaml # uncomment to expose dify-api port to host # ports: # - "5001:5001" ``` Additionally, start the API server with the correct host and port configuration using: ```bash flask run --host 0.0.0.0 --port=5001 --debug ``` Ensure middleware services are running by executing: ```bash cd docker cp middleware.env.example middleware.env docker compose -f docker-compose.middleware.yaml up -d ``` Check that no firewall rules are blocking port 5001, and verify that the Python environment is correctly set up with Python 3.12 and all dependencies are installed using Poetry <sup>[[1]](https://github.com/langgenius/dify/issues/14160)</sup><sup>[[2]](https://github.com/langgenius/dify/issues/13806)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.* --- <sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/1f6630e1-248e-484e-9286-fa38c0a20ccc?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/1f6630e1-248e-484e-9286-fa38c0a20ccc?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/1f6630e1-248e-484e-9286-fa38c0a20ccc?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/1f6630e1-248e-484e-9286-fa38c0a20ccc?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/1f6630e1-248e-484e-9286-fa38c0a20ccc?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/1f6630e1-248e-484e-9286-fa38c0a20ccc?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/1f6630e1-248e-484e-9286-fa38c0a20ccc?feedback_type=other)</sup>
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#8801