An error occurs when I use openapi of chatbot's chatflow #5498

Closed
opened 2026-02-21 18:11:16 -05:00 by yindo · 2 comments
Owner

Originally created by @jiegod on GitHub (Sep 9, 2024).

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.7.1

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

image
An error occurs when I use openapi of chatbot's chatflow,the error message: The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application

this is error message:

2024-09-06 06:53:58,123.123 INFO [Thread-7 (process_request_thread)] [base.py:1099] - BEGIN (implicit)
2024-09-06 06:53:58,139.139 INFO [Thread-7 (process_request_thread)] [base.py:1899] - SELECT api_tokens.id AS api_tokens_id, api_tokens.app_id AS api_tokens_app_id, api_tokens.tenant_id AS api_tokens_tenant_id, api_tokens.type AS api_tokens_type, api_tokens.token AS api_tokens_token, api_tokens.last_used_at AS api_tokens_last_used_at, api_tokens.created_at AS api_tokens_created_at 
FROM api_tokens 
WHERE api_tokens.token = %(token_1)s AND api_tokens.type = %(type_1)s 
 LIMIT %(param_1)s
2024-09-06 06:53:58,141.141 INFO [Thread-7 (process_request_thread)] [base.py:1904] - [cached since 134.4s ago] {'token_1': 'app-oLKV2FIcXGF7AnHxN24g9EZr', 'type_1': 'app', 'param_1': 1}
2024-09-06 06:53:58,490.490 INFO [Thread-7 (process_request_thread)] [base.py:1899] - UPDATE api_tokens SET last_used_at=%(last_used_at)s WHERE api_tokens.id = %(api_tokens_id)s::UUID
2024-09-06 06:53:58,490.490 INFO [Thread-7 (process_request_thread)] [base.py:1904] - [cached since 134.5s ago] {'last_used_at': datetime.datetime(2024, 9, 6, 6, 53, 58, 486345), 'api_tokens_id': '7554f4b6-1a22-44a3-836c-2ca68356ec20'}
2024-09-06 06:53:58,632.632 INFO [Thread-7 (process_request_thread)] [base.py:1142] - COMMIT
2024-09-06 06:53:58,783.783 INFO [Thread-7 (process_request_thread)] [base.py:1099] - BEGIN (implicit)
2024-09-06 06:53:58,787.787 INFO [Thread-7 (process_request_thread)] [base.py:1899] - SELECT api_tokens.id AS api_tokens_id, api_tokens.app_id AS api_tokens_app_id, api_tokens.tenant_id AS api_tokens_tenant_id, api_tokens.type AS api_tokens_type, api_tokens.token AS api_tokens_token, api_tokens.last_used_at AS api_tokens_last_used_at, api_tokens.created_at AS api_tokens_created_at 
FROM api_tokens 
WHERE api_tokens.id = %(pk_1)s::UUID
2024-09-06 06:53:58,820.820 INFO [Thread-7 (process_request_thread)] [base.py:1904] - [cached since 134.5s ago] {'pk_1': '7554f4b6-1a22-44a3-836c-2ca68356ec20'}
2024-09-06 06:53:59,156.156 INFO [Thread-7 (process_request_thread)] [base.py:1899] - SELECT apps.id AS apps_id, apps.tenant_id AS apps_tenant_id, apps.name AS apps_name, apps.description AS apps_description, apps.mode AS apps_mode, apps.icon_type AS apps_icon_type, apps.icon AS apps_icon, apps.icon_background AS apps_icon_background, apps.app_model_config_id AS apps_app_model_config_id, apps.workflow_id AS apps_workflow_id, apps.status AS apps_status, apps.enable_site AS apps_enable_site, apps.enable_api AS apps_enable_api, apps.api_rpm AS apps_api_rpm, apps.api_rph AS apps_api_rph, apps.is_demo AS apps_is_demo, apps.is_public AS apps_is_public, apps.is_universal AS apps_is_universal, apps.tracing AS apps_tracing, apps.max_active_requests AS apps_max_active_requests, apps.created_at AS apps_created_at, apps.updated_at AS apps_updated_at 
FROM apps 
WHERE apps.id = %(id_1)s::UUID 
 LIMIT %(param_1)s
2024-09-06 06:53:59,156.156 INFO [Thread-7 (process_request_thread)] [base.py:1904] - [cached since 134.6s ago] {'id_1': 'e1ec6d67-3971-4484-8ce3-584eb739b474', 'param_1': 1}
2024-09-06 06:53:59,307.307 INFO [Thread-7 (process_request_thread)] [base.py:1899] - SELECT tenants.id AS tenants_id, tenants.name AS tenants_name, tenants.encrypt_public_key AS tenants_encrypt_public_key, tenants.plan AS tenants_plan, tenants.status AS tenants_status, tenants.custom_config AS tenants_custom_config, tenants.created_at AS tenants_created_at, tenants.updated_at AS tenants_updated_at 
FROM tenants 
WHERE tenants.id = %(id_1)s::UUID 
 LIMIT %(param_1)s
2024-09-06 06:53:59,308.308 INFO [Thread-7 (process_request_thread)] [base.py:1904] - [cached since 134.6s ago] {'id_1': '29145f2a-c303-4d3f-a59e-21f00d04614c', 'param_1': 1}
2024-09-06 06:53:59,491.491 INFO [Thread-7 (process_request_thread)] [base.py:1899] - SELECT end_users.id AS end_users_id, end_users.tenant_id AS end_users_tenant_id, end_users.app_id AS end_users_app_id, end_users.type AS end_users_type, end_users.external_user_id AS end_users_external_user_id, end_users.name AS end_users_name, end_users.is_anonymous AS end_users_is_anonymous, end_users.session_id AS end_users_session_id, end_users.created_at AS end_users_created_at, end_users.updated_at AS end_users_updated_at 
FROM end_users 
WHERE end_users.tenant_id = %(tenant_id_1)s::UUID AND end_users.app_id = %(app_id_1)s::UUID AND end_users.session_id = %(session_id_1)s AND end_users.type = %(type_1)s 
 LIMIT %(param_1)s
2024-09-06 06:53:59,492.492 INFO [Thread-7 (process_request_thread)] [base.py:1904] - [cached since 134.6s ago] {'tenant_id_1': '29145f2a-c303-4d3f-a59e-21f00d04614c', 'app_id_1': 'e1ec6d67-3971-4484-8ce3-584eb739b474', 'session_id_1': 'jack.www@binance.com', 'type_1': 'service_api', 'param_1': 1}
2024-09-06 06:54:01,268.268 INFO [Thread-7 (process_request_thread)] [base.py:1899] - SELECT workflows.id AS workflows_id, workflows.tenant_id AS workflows_tenant_id, workflows.app_id AS workflows_app_id, workflows.type AS workflows_type, workflows.version AS workflows_version, workflows.graph AS workflows_graph, workflows.features AS workflows_features, workflows.created_by AS workflows_created_by, workflows.created_at AS workflows_created_at, workflows.updated_by AS workflows_updated_by, workflows.updated_at AS workflows_updated_at, workflows.environment_variables AS workflows_environment_variables, workflows.conversation_variables AS workflows_conversation_variables 
FROM workflows 
WHERE workflows.tenant_id = %(tenant_id_1)s::UUID AND workflows.app_id = %(app_id_1)s::UUID AND workflows.id = %(id_1)s::UUID 
 LIMIT %(param_1)s
2024-09-06 06:54:01,269.269 INFO [Thread-7 (process_request_thread)] [base.py:1904] - [generated in 0.00097s] {'tenant_id_1': '29145f2a-c303-4d3f-a59e-21f00d04614c', 'app_id_1': 'e1ec6d67-3971-4484-8ce3-584eb739b474', 'id_1': 'cbb9778e-c954-4167-9d21-707c1c46994a', 'param_1': 1}
2024-09-06 06:54:02,090.090 INFO [Thread-7 (process_request_thread)] [base.py:1899] - SELECT apps.id AS apps_id, apps.tenant_id AS apps_tenant_id, apps.name AS apps_name, apps.description AS apps_description, apps.mode AS apps_mode, apps.icon_type AS apps_icon_type, apps.icon AS apps_icon, apps.icon_background AS apps_icon_background, apps.app_model_config_id AS apps_app_model_config_id, apps.workflow_id AS apps_workflow_id, apps.status AS apps_status, apps.enable_site AS apps_enable_site, apps.enable_api AS apps_enable_api, apps.api_rpm AS apps_api_rpm, apps.api_rph AS apps_api_rph, apps.is_demo AS apps_is_demo, apps.is_public AS apps_is_public, apps.is_universal AS apps_is_universal, apps.tracing AS apps_tracing, apps.max_active_requests AS apps_max_active_requests, apps.created_at AS apps_created_at, apps.updated_at AS apps_updated_at 
FROM apps 
WHERE apps.id = %(id_1)s::UUID 
 LIMIT %(param_1)s
2024-09-06 06:54:02,091.091 INFO [Thread-7 (process_request_thread)] [base.py:1904] - [cached since 137.5s ago] {'id_1': 'e1ec6d67-3971-4484-8ce3-584eb739b474', 'param_1': 1}
2024-09-06 06:54:02,252.252 INFO [Thread-7 (process_request_thread)] [base.py:1899] - INSERT INTO conversations (app_id, app_model_config_id, model_provider, override_model_configs, model_id, mode, name, summary, inputs, introduction, system_instruction, system_instruction_tokens, status, invoke_from, from_source, from_end_user_id, from_account_id, read_at, read_account_id, dialogue_count) VALUES (%(app_id)s::UUID, %(app_model_config_id)s::UUID, %(model_provider)s, %(override_model_configs)s, %(model_id)s, %(mode)s, %(name)s, %(summary)s, %(inputs)s, %(introduction)s, %(system_instruction)s, %(system_instruction_tokens)s, %(status)s, %(invoke_from)s, %(from_source)s, %(from_end_user_id)s::UUID, %(from_account_id)s::UUID, %(read_at)s, %(read_account_id)s::UUID, %(dialogue_count)s) RETURNING conversations.id, conversations.created_at, conversations.updated_at, conversations.is_deleted
2024-09-06 06:54:02,253.253 INFO [Thread-7 (process_request_thread)] [base.py:1904] - [generated in 0.00084s] {'app_id': 'e1ec6d67-3971-4484-8ce3-584eb739b474', 'app_model_config_id': None, 'model_provider': None, 'override_model_configs': None, 'model_id': None, 'mode': 'advanced-chat', 'name': 'New conversation', 'summary': None, 'inputs': '{"user_permissions_list": "123", "user_page_location": "test1", "user_email": "jack.www@binance.com", "user_questions": "What is Spot net revenue 2024-07?"}', 'introduction': '', 'system_instruction': '', 'system_instruction_tokens': 0, 'status': 'normal', 'invoke_from': 'service-api', 'from_source': 'api', 'from_end_user_id': '0a2e3881-c52f-4dd4-9a83-2fa7d1c30181', 'from_account_id': None, 'read_at': None, 'read_account_id': None, 'dialogue_count': 0}
2024-09-06 06:54:02,400.400 INFO [Thread-7 (process_request_thread)] [base.py:1142] - COMMIT
2024-09-06 06:54:02,546.546 INFO [Thread-7 (process_request_thread)] [base.py:1099] - BEGIN (implicit)
2024-09-06 06:54:02,551.551 INFO [Thread-7 (process_request_thread)] [base.py:1899] - SELECT conversations.id, conversations.app_id, conversations.app_model_config_id, conversations.model_provider, conversations.override_model_configs, conversations.model_id, conversations.mode, conversations.name, conversations.summary, conversations.inputs, conversations.introduction, conversations.system_instruction, conversations.system_instruction_tokens, conversations.status, conversations.invoke_from, conversations.from_source, conversations.from_end_user_id, conversations.from_account_id, conversations.read_at, conversations.read_account_id, conversations.dialogue_count, conversations.created_at, conversations.updated_at, conversations.is_deleted 
FROM conversations 
WHERE conversations.id = %(pk_1)s::UUID
2024-09-06 06:54:02,551.551 INFO [Thread-7 (process_request_thread)] [base.py:1904] - [generated in 0.00050s] {'pk_1': '3cc266cf-398e-4485-8b44-0763802a7ee5'}
2024-09-06 06:54:02,828.828 INFO [Thread-7 (process_request_thread)] [base.py:1899] - INSERT INTO messages (app_id, model_provider, model_id, override_model_configs, conversation_id, inputs, query, message, message_tokens, message_unit_price, message_price_unit, answer, answer_tokens, answer_unit_price, answer_price_unit, provider_response_latency, total_price, currency, error, message_metadata, invoke_from, from_source, from_end_user_id, from_account_id, workflow_run_id) VALUES (%(app_id)s::UUID, %(model_provider)s, %(model_id)s, %(override_model_configs)s, %(conversation_id)s::UUID, %(inputs)s, %(query)s, %(message)s, %(message_tokens)s, %(message_unit_price)s, %(message_price_unit)s, %(answer)s, %(answer_tokens)s, %(answer_unit_price)s, %(answer_price_unit)s, %(provider_response_latency)s, %(total_price)s, %(currency)s, %(error)s, %(message_metadata)s, %(invoke_from)s, %(from_source)s, %(from_end_user_id)s::UUID, %(from_account_id)s::UUID, %(workflow_run_id)s::UUID) RETURNING messages.id, messages.status, messages.created_at, messages.updated_at, messages.agent_based
2024-09-06 06:54:02,828.828 INFO [Thread-7 (process_request_thread)] [base.py:1904] - [generated in 0.00074s] {'app_id': 'e1ec6d67-3971-4484-8ce3-584eb739b474', 'model_provider': None, 'model_id': None, 'override_model_configs': None, 'conversation_id': '3cc266cf-398e-4485-8b44-0763802a7ee5', 'inputs': '{"user_permissions_list": "123", "user_page_location": "test1", "user_email": "jack.www@binance.com", "user_questions": "What is Spot net revenue 2024-07?"}', 'query': 'What is Spot net revenue 2024-07?', 'message': '""', 'message_tokens': 0, 'message_unit_price': 0, 'message_price_unit': 0, 'answer': '', 'answer_tokens': 0, 'answer_unit_price': 0, 'answer_price_unit': 0, 'provider_response_latency': 0, 'total_price': 0, 'currency': 'USD', 'error': None, 'message_metadata': None, 'invoke_from': 'service-api', 'from_source': 'api', 'from_end_user_id': '0a2e3881-c52f-4dd4-9a83-2fa7d1c30181', 'from_account_id': None, 'workflow_run_id': None}
2024-09-06 06:54:02,972.972 INFO [Thread-7 (process_request_thread)] [base.py:1142] - COMMIT
2024-09-06 06:54:03,122.122 INFO [Thread-7 (process_request_thread)] [base.py:1099] - BEGIN (implicit)
2024-09-06 06:54:03,127.127 INFO [Thread-7 (process_request_thread)] [base.py:1899] - SELECT messages.id, messages.app_id, messages.model_provider, messages.model_id, messages.override_model_configs, messages.conversation_id, messages.inputs, messages.query, messages.message, messages.message_tokens, messages.message_unit_price, messages.message_price_unit, messages.answer, messages.answer_tokens, messages.answer_unit_price, messages.answer_price_unit, messages.provider_response_latency, messages.total_price, messages.currency, messages.status, messages.error, messages.message_metadata, messages.invoke_from, messages.from_source, messages.from_end_user_id, messages.from_account_id, messages.created_at, messages.updated_at, messages.agent_based, messages.workflow_run_id 
FROM messages 
WHERE messages.id = %(pk_1)s::UUID
2024-09-06 06:54:03,127.127 INFO [Thread-7 (process_request_thread)] [base.py:1904] - [generated in 0.00065s] {'pk_1': 'd82e1e05-f371-4ded-8846-2203c3a04511'}
2024-09-06 06:54:03,407.407 INFO [Thread-7 (process_request_thread)] [base.py:1899] - SELECT workflows.id AS workflows_id, workflows.tenant_id AS workflows_tenant_id, workflows.app_id AS workflows_app_id, workflows.type AS workflows_type, workflows.version AS workflows_version, workflows.graph AS workflows_graph, workflows.features AS workflows_features, workflows.created_by AS workflows_created_by, workflows.created_at AS workflows_created_at, workflows.updated_by AS workflows_updated_by, workflows.updated_at AS workflows_updated_at, workflows.environment_variables AS workflows_environment_variables, workflows.conversation_variables AS workflows_conversation_variables 
FROM workflows 
WHERE workflows.id = %(pk_1)s::UUID
2024-09-06 06:54:03,408.408 INFO [Thread-7 (process_request_thread)] [base.py:1904] - [generated in 0.00101s] {'pk_1': 'cbb9778e-c954-4167-9d21-707c1c46994a'}
2024-09-06 06:54:03,752.752 INFO [Thread-7 (process_request_thread)] [base.py:1899] - SELECT conversations.id AS conversations_id, conversations.app_id AS conversations_app_id, conversations.app_model_config_id AS conversations_app_model_config_id, conversations.model_provider AS conversations_model_provider, conversations.model_id AS conversations_model_id, conversations.mode AS conversations_mode, conversations.name AS conversations_name, conversations.summary AS conversations_summary, conversations.inputs AS conversations_inputs, conversations.introduction AS conversations_introduction, conversations.system_instruction AS conversations_system_instruction, conversations.system_instruction_tokens AS conversations_system_instruction_tokens, conversations.status AS conversations_status, conversations.invoke_from AS conversations_invoke_from, conversations.from_source AS conversations_from_source, conversations.from_end_user_id AS conversations_from_end_user_id, conversations.from_account_id AS conversations_from_account_id, conversations.read_at AS conversations_read_at, conversations.read_account_id AS conversations_read_account_id, conversations.dialogue_count AS conversations_dialogue_count, conversations.created_at AS conversations_created_at, conversations.updated_at AS conversations_updated_at, conversations.is_deleted AS conversations_is_deleted 
FROM conversations 
WHERE conversations.id = %(pk_1)s::UUID
2024-09-06 06:54:03,752.752 INFO [Thread-7 (process_request_thread)] [base.py:1904] - [generated in 0.00055s] {'pk_1': '3cc266cf-398e-4485-8b44-0763802a7ee5'}
2024-09-06 06:54:03,887.887 INFO [Thread-7 (process_request_thread)] [base.py:1899] - UPDATE conversations SET override_model_configs=%(override_model_configs)s WHERE conversations.id = %(conversations_id)s::UUID
2024-09-06 06:54:03,887.887 INFO [Thread-7 (process_request_thread)] [base.py:1904] - [generated in 0.00057s] {'override_model_configs': '{"opening_statement": "", "suggested_questions": [], "suggested_questions_after_answer": {"enabled": false}, "text_to_speech": {"enabled": false, "la ... (120 characters truncated) ... d_avoidance": {"enabled": false}, "file_upload": {"image": {"enabled": false, "number_limits": 3, "transfer_methods": ["local_file", "remote_url"]}}}', 'conversations_id': '3cc266cf-398e-4485-8b44-0763802a7ee5'}
2024-09-06 06:54:04,028.028 INFO [Thread-7 (process_request_thread)] [base.py:1142] - COMMIT
2024-09-06 06:54:04,172.172 INFO [Thread-7 (process_request_thread)] [base.py:1099] - BEGIN (implicit)
2024-09-06 06:54:04,175.175 INFO [Thread-7 (process_request_thread)] [base.py:1899] - SELECT conversations.id AS conversations_id, conversations.app_id AS conversations_app_id, conversations.app_model_config_id AS conversations_app_model_config_id, conversations.model_provider AS conversations_model_provider, conversations.override_model_configs AS conversations_override_model_configs, conversations.model_id AS conversations_model_id, conversations.mode AS conversations_mode, conversations.name AS conversations_name, conversations.summary AS conversations_summary, conversations.inputs AS conversations_inputs, conversations.introduction AS conversations_introduction, conversations.system_instruction AS conversations_system_instruction, conversations.system_instruction_tokens AS conversations_system_instruction_tokens, conversations.status AS conversations_status, conversations.invoke_from AS conversations_invoke_from, conversations.from_source AS conversations_from_source, conversations.from_end_user_id AS conversations_from_end_user_id, conversations.from_account_id AS conversations_from_account_id, conversations.read_at AS conversations_read_at, conversations.read_account_id AS conversations_read_account_id, conversations.dialogue_count AS conversations_dialogue_count, conversations.created_at AS conversations_created_at, conversations.updated_at AS conversations_updated_at, conversations.is_deleted AS conversations_is_deleted 
FROM conversations 
WHERE conversations.id = %(pk_1)s::UUID
2024-09-06 06:54:04,175.175 INFO [Thread-7 (process_request_thread)] [base.py:1904] - [generated in 0.00044s] {'pk_1': '3cc266cf-398e-4485-8b44-0763802a7ee5'}
2024-09-06 06:54:04,488.488 INFO [Thread-7 (process_request_thread)] [base.py:1899] - SELECT messages.id AS messages_id, messages.app_id AS messages_app_id, messages.model_provider AS messages_model_provider, messages.model_id AS messages_model_id, messages.override_model_configs AS messages_override_model_configs, messages.conversation_id AS messages_conversation_id, messages.inputs AS messages_inputs, messages.query AS messages_query, messages.message AS messages_message, messages.message_tokens AS messages_message_tokens, messages.message_unit_price AS messages_message_unit_price, messages.message_price_unit AS messages_message_price_unit, messages.answer AS messages_answer, messages.answer_tokens AS messages_answer_tokens, messages.answer_unit_price AS messages_answer_unit_price, messages.answer_price_unit AS messages_answer_price_unit, messages.provider_response_latency AS messages_provider_response_latency, messages.total_price AS messages_total_price, messages.currency AS messages_currency, messages.status AS messages_status, messages.error AS messages_error, messages.message_metadata AS messages_message_metadata, messages.invoke_from AS messages_invoke_from, messages.from_source AS messages_from_source, messages.from_end_user_id AS messages_from_end_user_id, messages.from_account_id AS messages_from_account_id, messages.created_at AS messages_created_at, messages.updated_at AS messages_updated_at, messages.agent_based AS messages_agent_based, messages.workflow_run_id AS messages_workflow_run_id 
FROM messages 
WHERE messages.id = %(pk_1)s::UUID
2024-09-06 06:54:04,488.488 INFO [Thread-7 (process_request_thread)] [base.py:1904] - [generated in 0.00046s] {'pk_1': 'd82e1e05-f371-4ded-8846-2203c3a04511'}
2024-09-06 06:54:04,624.624 ERROR [Thread-7 (process_request_thread)] [completion.py:143] - internal server error.
Traceback (most recent call last):
  File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/.venv/lib/python3.10/site-packages/redis/connection.py", line 277, in connect
    sock = self.retry.call_with_retry(
  File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/.venv/lib/python3.10/site-packages/redis/retry.py", line 62, in call_with_retry
    return do()
  File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/.venv/lib/python3.10/site-packages/redis/connection.py", line 278, in <lambda>
    lambda: self._connect(), lambda error: self.disconnect(error)
  File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/.venv/lib/python3.10/site-packages/redis/connection.py", line 639, in _connect
    raise err
  File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/.venv/lib/python3.10/site-packages/redis/connection.py", line 627, in _connect
    sock.connect(socket_address)
ConnectionRefusedError: [Errno 61] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/controllers/service_api/app/completion.py", line 116, in post
    response = AppGenerateService.generate(
  File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/services/app_generate_service.py", line 65, in generate
    return rate_limit.generate(AdvancedChatAppGenerator().generate(
  File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/core/app/apps/advanced_chat/app_generator.py", line 123, in generate
    return self._generate(
  File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/core/app/apps/advanced_chat/app_generator.py", line 222, in _generate
    queue_manager = MessageBasedAppQueueManager(
  File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/core/app/apps/message_based_app_queue_manager.py", line 22, in __init__
    super().__init__(task_id, user_id, invoke_from)
  File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/core/app/apps/base_app_queue_manager.py", line 38, in __init__
    redis_client.setex(AppQueueManager._generate_task_belong_cache_key(self._task_id), 1800,
  File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/.venv/lib/python3.10/site-packages/redis/commands/core.py", line 2358, in setex
    return self.execute_command("SETEX", name, time, value)
  File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/.venv/lib/python3.10/site-packages/redis/client.py", line 545, in execute_command
    conn = self.connection or pool.get_connection(command_name, **options)
  File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/.venv/lib/python3.10/site-packages/redis/connection.py", line 1074, in get_connection
    connection.connect()
  File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/.venv/lib/python3.10/site-packages/redis/connection.py", line 283, in connect
    raise ConnectionError(self._error_message(e))
redis.exceptions.ConnectionError: Error 61 connecting to localhost:6379. Connection refused.
2024-09-06 06:54:04,635.635 ERROR [Thread-7 (process_request_thread)] [app.py:838] - Exception on /v1/chat-messages [POST]
Traceback (most recent call last):
  File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/.venv/lib/python3.10/site-packages/redis/connection.py", line 277, in connect
    sock = self.retry.call_with_retry(
  File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/.venv/lib/python3.10/site-packages/redis/retry.py", line 62, in call_with_retry
    return do()
  File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/.venv/lib/python3.10/site-packages/redis/connection.py", line 278, in <lambda>
    lambda: self._connect(), lambda error: self.disconnect(error)
  File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/.venv/lib/python3.10/site-packages/redis/connection.py", line 639, in _connect
    raise err
  File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/.venv/lib/python3.10/site-packages/redis/connection.py", line 627, in _connect
    sock.connect(socket_address)
ConnectionRefusedError: [Errno 61] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/controllers/service_api/app/completion.py", line 116, in post
    response = AppGenerateService.generate(
  File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/services/app_generate_service.py", line 65, in generate
    return rate_limit.generate(AdvancedChatAppGenerator().generate(
  File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/core/app/apps/advanced_chat/app_generator.py", line 123, in generate
    return self._generate(
  File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/core/app/apps/advanced_chat/app_generator.py", line 222, in _generate
    queue_manager = MessageBasedAppQueueManager(
  File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/core/app/apps/message_based_app_queue_manager.py", line 22, in __init__
    super().__init__(task_id, user_id, invoke_from)
  File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/core/app/apps/base_app_queue_manager.py", line 38, in __init__
    redis_client.setex(AppQueueManager._generate_task_belong_cache_key(self._task_id), 1800,
  File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/.venv/lib/python3.10/site-packages/redis/commands/core.py", line 2358, in setex
    return self.execute_command("SETEX", name, time, value)
  File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/.venv/lib/python3.10/site-packages/redis/client.py", line 545, in execute_command
    conn = self.connection or pool.get_connection(command_name, **options)
  File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/.venv/lib/python3.10/site-packages/redis/connection.py", line 1074, in get_connection
    connection.connect()
  File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/.venv/lib/python3.10/site-packages/redis/connection.py", line 283, in connect
    raise ConnectionError(self._error_message(e))
redis.exceptions.ConnectionError: Error 61 connecting to localhost:6379. Connection refused.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/.venv/lib/python3.10/site-packages/flask/app.py", line 880, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/.venv/lib/python3.10/site-packages/flask/app.py", line 865, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
  File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/.venv/lib/python3.10/site-packages/flask_restful/__init__.py", line 489, in wrapper
    resp = resource(*args, **kwargs)
  File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/.venv/lib/python3.10/site-packages/flask/views.py", line 110, in view
    return current_app.ensure_sync(self.dispatch_request)(**kwargs)  # type: ignore[no-any-return]
  File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/.venv/lib/python3.10/site-packages/flask_restful/__init__.py", line 604, in dispatch_request
    resp = meth(*args, **kwargs)
  File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/controllers/service_api/wraps.py", line 75, in decorated_view
    return view_func(*args, **kwargs)
  File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/controllers/service_api/app/completion.py", line 144, in post
    raise InternalServerError()
werkzeug.exceptions.InternalServerError: 500 Internal Server Error: The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.
2024-09-06 06:54:04,637.637 INFO [Thread-7 (process_request_thread)] [base.py:1125] - ROLLBACK
2024-09-06 06:54:04,771.771 INFO [Thread-7 (process_request_thread)] [_internal.py:97] - 127.0.0.1 - - [06/Sep/2024 06:54:04] "POST /v1/chat-messages HTTP/1.1" 500 -

✔️ Expected Behavior

it should return my normal message

Actual Behavior

{
"code": "internal_server_error",
"message": "The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.",
"status": 500
}

Originally created by @jiegod on GitHub (Sep 9, 2024). ### 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.7.1 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce ![image](https://github.com/user-attachments/assets/67da90e4-8116-461c-a467-8f8c046e5788) An error occurs when I use openapi of chatbot's chatflow,the error message: The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application this is error message: ``` 2024-09-06 06:53:58,123.123 INFO [Thread-7 (process_request_thread)] [base.py:1099] - BEGIN (implicit) 2024-09-06 06:53:58,139.139 INFO [Thread-7 (process_request_thread)] [base.py:1899] - SELECT api_tokens.id AS api_tokens_id, api_tokens.app_id AS api_tokens_app_id, api_tokens.tenant_id AS api_tokens_tenant_id, api_tokens.type AS api_tokens_type, api_tokens.token AS api_tokens_token, api_tokens.last_used_at AS api_tokens_last_used_at, api_tokens.created_at AS api_tokens_created_at FROM api_tokens WHERE api_tokens.token = %(token_1)s AND api_tokens.type = %(type_1)s LIMIT %(param_1)s 2024-09-06 06:53:58,141.141 INFO [Thread-7 (process_request_thread)] [base.py:1904] - [cached since 134.4s ago] {'token_1': 'app-oLKV2FIcXGF7AnHxN24g9EZr', 'type_1': 'app', 'param_1': 1} 2024-09-06 06:53:58,490.490 INFO [Thread-7 (process_request_thread)] [base.py:1899] - UPDATE api_tokens SET last_used_at=%(last_used_at)s WHERE api_tokens.id = %(api_tokens_id)s::UUID 2024-09-06 06:53:58,490.490 INFO [Thread-7 (process_request_thread)] [base.py:1904] - [cached since 134.5s ago] {'last_used_at': datetime.datetime(2024, 9, 6, 6, 53, 58, 486345), 'api_tokens_id': '7554f4b6-1a22-44a3-836c-2ca68356ec20'} 2024-09-06 06:53:58,632.632 INFO [Thread-7 (process_request_thread)] [base.py:1142] - COMMIT 2024-09-06 06:53:58,783.783 INFO [Thread-7 (process_request_thread)] [base.py:1099] - BEGIN (implicit) 2024-09-06 06:53:58,787.787 INFO [Thread-7 (process_request_thread)] [base.py:1899] - SELECT api_tokens.id AS api_tokens_id, api_tokens.app_id AS api_tokens_app_id, api_tokens.tenant_id AS api_tokens_tenant_id, api_tokens.type AS api_tokens_type, api_tokens.token AS api_tokens_token, api_tokens.last_used_at AS api_tokens_last_used_at, api_tokens.created_at AS api_tokens_created_at FROM api_tokens WHERE api_tokens.id = %(pk_1)s::UUID 2024-09-06 06:53:58,820.820 INFO [Thread-7 (process_request_thread)] [base.py:1904] - [cached since 134.5s ago] {'pk_1': '7554f4b6-1a22-44a3-836c-2ca68356ec20'} 2024-09-06 06:53:59,156.156 INFO [Thread-7 (process_request_thread)] [base.py:1899] - SELECT apps.id AS apps_id, apps.tenant_id AS apps_tenant_id, apps.name AS apps_name, apps.description AS apps_description, apps.mode AS apps_mode, apps.icon_type AS apps_icon_type, apps.icon AS apps_icon, apps.icon_background AS apps_icon_background, apps.app_model_config_id AS apps_app_model_config_id, apps.workflow_id AS apps_workflow_id, apps.status AS apps_status, apps.enable_site AS apps_enable_site, apps.enable_api AS apps_enable_api, apps.api_rpm AS apps_api_rpm, apps.api_rph AS apps_api_rph, apps.is_demo AS apps_is_demo, apps.is_public AS apps_is_public, apps.is_universal AS apps_is_universal, apps.tracing AS apps_tracing, apps.max_active_requests AS apps_max_active_requests, apps.created_at AS apps_created_at, apps.updated_at AS apps_updated_at FROM apps WHERE apps.id = %(id_1)s::UUID LIMIT %(param_1)s 2024-09-06 06:53:59,156.156 INFO [Thread-7 (process_request_thread)] [base.py:1904] - [cached since 134.6s ago] {'id_1': 'e1ec6d67-3971-4484-8ce3-584eb739b474', 'param_1': 1} 2024-09-06 06:53:59,307.307 INFO [Thread-7 (process_request_thread)] [base.py:1899] - SELECT tenants.id AS tenants_id, tenants.name AS tenants_name, tenants.encrypt_public_key AS tenants_encrypt_public_key, tenants.plan AS tenants_plan, tenants.status AS tenants_status, tenants.custom_config AS tenants_custom_config, tenants.created_at AS tenants_created_at, tenants.updated_at AS tenants_updated_at FROM tenants WHERE tenants.id = %(id_1)s::UUID LIMIT %(param_1)s 2024-09-06 06:53:59,308.308 INFO [Thread-7 (process_request_thread)] [base.py:1904] - [cached since 134.6s ago] {'id_1': '29145f2a-c303-4d3f-a59e-21f00d04614c', 'param_1': 1} 2024-09-06 06:53:59,491.491 INFO [Thread-7 (process_request_thread)] [base.py:1899] - SELECT end_users.id AS end_users_id, end_users.tenant_id AS end_users_tenant_id, end_users.app_id AS end_users_app_id, end_users.type AS end_users_type, end_users.external_user_id AS end_users_external_user_id, end_users.name AS end_users_name, end_users.is_anonymous AS end_users_is_anonymous, end_users.session_id AS end_users_session_id, end_users.created_at AS end_users_created_at, end_users.updated_at AS end_users_updated_at FROM end_users WHERE end_users.tenant_id = %(tenant_id_1)s::UUID AND end_users.app_id = %(app_id_1)s::UUID AND end_users.session_id = %(session_id_1)s AND end_users.type = %(type_1)s LIMIT %(param_1)s 2024-09-06 06:53:59,492.492 INFO [Thread-7 (process_request_thread)] [base.py:1904] - [cached since 134.6s ago] {'tenant_id_1': '29145f2a-c303-4d3f-a59e-21f00d04614c', 'app_id_1': 'e1ec6d67-3971-4484-8ce3-584eb739b474', 'session_id_1': 'jack.www@binance.com', 'type_1': 'service_api', 'param_1': 1} 2024-09-06 06:54:01,268.268 INFO [Thread-7 (process_request_thread)] [base.py:1899] - SELECT workflows.id AS workflows_id, workflows.tenant_id AS workflows_tenant_id, workflows.app_id AS workflows_app_id, workflows.type AS workflows_type, workflows.version AS workflows_version, workflows.graph AS workflows_graph, workflows.features AS workflows_features, workflows.created_by AS workflows_created_by, workflows.created_at AS workflows_created_at, workflows.updated_by AS workflows_updated_by, workflows.updated_at AS workflows_updated_at, workflows.environment_variables AS workflows_environment_variables, workflows.conversation_variables AS workflows_conversation_variables FROM workflows WHERE workflows.tenant_id = %(tenant_id_1)s::UUID AND workflows.app_id = %(app_id_1)s::UUID AND workflows.id = %(id_1)s::UUID LIMIT %(param_1)s 2024-09-06 06:54:01,269.269 INFO [Thread-7 (process_request_thread)] [base.py:1904] - [generated in 0.00097s] {'tenant_id_1': '29145f2a-c303-4d3f-a59e-21f00d04614c', 'app_id_1': 'e1ec6d67-3971-4484-8ce3-584eb739b474', 'id_1': 'cbb9778e-c954-4167-9d21-707c1c46994a', 'param_1': 1} 2024-09-06 06:54:02,090.090 INFO [Thread-7 (process_request_thread)] [base.py:1899] - SELECT apps.id AS apps_id, apps.tenant_id AS apps_tenant_id, apps.name AS apps_name, apps.description AS apps_description, apps.mode AS apps_mode, apps.icon_type AS apps_icon_type, apps.icon AS apps_icon, apps.icon_background AS apps_icon_background, apps.app_model_config_id AS apps_app_model_config_id, apps.workflow_id AS apps_workflow_id, apps.status AS apps_status, apps.enable_site AS apps_enable_site, apps.enable_api AS apps_enable_api, apps.api_rpm AS apps_api_rpm, apps.api_rph AS apps_api_rph, apps.is_demo AS apps_is_demo, apps.is_public AS apps_is_public, apps.is_universal AS apps_is_universal, apps.tracing AS apps_tracing, apps.max_active_requests AS apps_max_active_requests, apps.created_at AS apps_created_at, apps.updated_at AS apps_updated_at FROM apps WHERE apps.id = %(id_1)s::UUID LIMIT %(param_1)s 2024-09-06 06:54:02,091.091 INFO [Thread-7 (process_request_thread)] [base.py:1904] - [cached since 137.5s ago] {'id_1': 'e1ec6d67-3971-4484-8ce3-584eb739b474', 'param_1': 1} 2024-09-06 06:54:02,252.252 INFO [Thread-7 (process_request_thread)] [base.py:1899] - INSERT INTO conversations (app_id, app_model_config_id, model_provider, override_model_configs, model_id, mode, name, summary, inputs, introduction, system_instruction, system_instruction_tokens, status, invoke_from, from_source, from_end_user_id, from_account_id, read_at, read_account_id, dialogue_count) VALUES (%(app_id)s::UUID, %(app_model_config_id)s::UUID, %(model_provider)s, %(override_model_configs)s, %(model_id)s, %(mode)s, %(name)s, %(summary)s, %(inputs)s, %(introduction)s, %(system_instruction)s, %(system_instruction_tokens)s, %(status)s, %(invoke_from)s, %(from_source)s, %(from_end_user_id)s::UUID, %(from_account_id)s::UUID, %(read_at)s, %(read_account_id)s::UUID, %(dialogue_count)s) RETURNING conversations.id, conversations.created_at, conversations.updated_at, conversations.is_deleted 2024-09-06 06:54:02,253.253 INFO [Thread-7 (process_request_thread)] [base.py:1904] - [generated in 0.00084s] {'app_id': 'e1ec6d67-3971-4484-8ce3-584eb739b474', 'app_model_config_id': None, 'model_provider': None, 'override_model_configs': None, 'model_id': None, 'mode': 'advanced-chat', 'name': 'New conversation', 'summary': None, 'inputs': '{"user_permissions_list": "123", "user_page_location": "test1", "user_email": "jack.www@binance.com", "user_questions": "What is Spot net revenue 2024-07?"}', 'introduction': '', 'system_instruction': '', 'system_instruction_tokens': 0, 'status': 'normal', 'invoke_from': 'service-api', 'from_source': 'api', 'from_end_user_id': '0a2e3881-c52f-4dd4-9a83-2fa7d1c30181', 'from_account_id': None, 'read_at': None, 'read_account_id': None, 'dialogue_count': 0} 2024-09-06 06:54:02,400.400 INFO [Thread-7 (process_request_thread)] [base.py:1142] - COMMIT 2024-09-06 06:54:02,546.546 INFO [Thread-7 (process_request_thread)] [base.py:1099] - BEGIN (implicit) 2024-09-06 06:54:02,551.551 INFO [Thread-7 (process_request_thread)] [base.py:1899] - SELECT conversations.id, conversations.app_id, conversations.app_model_config_id, conversations.model_provider, conversations.override_model_configs, conversations.model_id, conversations.mode, conversations.name, conversations.summary, conversations.inputs, conversations.introduction, conversations.system_instruction, conversations.system_instruction_tokens, conversations.status, conversations.invoke_from, conversations.from_source, conversations.from_end_user_id, conversations.from_account_id, conversations.read_at, conversations.read_account_id, conversations.dialogue_count, conversations.created_at, conversations.updated_at, conversations.is_deleted FROM conversations WHERE conversations.id = %(pk_1)s::UUID 2024-09-06 06:54:02,551.551 INFO [Thread-7 (process_request_thread)] [base.py:1904] - [generated in 0.00050s] {'pk_1': '3cc266cf-398e-4485-8b44-0763802a7ee5'} 2024-09-06 06:54:02,828.828 INFO [Thread-7 (process_request_thread)] [base.py:1899] - INSERT INTO messages (app_id, model_provider, model_id, override_model_configs, conversation_id, inputs, query, message, message_tokens, message_unit_price, message_price_unit, answer, answer_tokens, answer_unit_price, answer_price_unit, provider_response_latency, total_price, currency, error, message_metadata, invoke_from, from_source, from_end_user_id, from_account_id, workflow_run_id) VALUES (%(app_id)s::UUID, %(model_provider)s, %(model_id)s, %(override_model_configs)s, %(conversation_id)s::UUID, %(inputs)s, %(query)s, %(message)s, %(message_tokens)s, %(message_unit_price)s, %(message_price_unit)s, %(answer)s, %(answer_tokens)s, %(answer_unit_price)s, %(answer_price_unit)s, %(provider_response_latency)s, %(total_price)s, %(currency)s, %(error)s, %(message_metadata)s, %(invoke_from)s, %(from_source)s, %(from_end_user_id)s::UUID, %(from_account_id)s::UUID, %(workflow_run_id)s::UUID) RETURNING messages.id, messages.status, messages.created_at, messages.updated_at, messages.agent_based 2024-09-06 06:54:02,828.828 INFO [Thread-7 (process_request_thread)] [base.py:1904] - [generated in 0.00074s] {'app_id': 'e1ec6d67-3971-4484-8ce3-584eb739b474', 'model_provider': None, 'model_id': None, 'override_model_configs': None, 'conversation_id': '3cc266cf-398e-4485-8b44-0763802a7ee5', 'inputs': '{"user_permissions_list": "123", "user_page_location": "test1", "user_email": "jack.www@binance.com", "user_questions": "What is Spot net revenue 2024-07?"}', 'query': 'What is Spot net revenue 2024-07?', 'message': '""', 'message_tokens': 0, 'message_unit_price': 0, 'message_price_unit': 0, 'answer': '', 'answer_tokens': 0, 'answer_unit_price': 0, 'answer_price_unit': 0, 'provider_response_latency': 0, 'total_price': 0, 'currency': 'USD', 'error': None, 'message_metadata': None, 'invoke_from': 'service-api', 'from_source': 'api', 'from_end_user_id': '0a2e3881-c52f-4dd4-9a83-2fa7d1c30181', 'from_account_id': None, 'workflow_run_id': None} 2024-09-06 06:54:02,972.972 INFO [Thread-7 (process_request_thread)] [base.py:1142] - COMMIT 2024-09-06 06:54:03,122.122 INFO [Thread-7 (process_request_thread)] [base.py:1099] - BEGIN (implicit) 2024-09-06 06:54:03,127.127 INFO [Thread-7 (process_request_thread)] [base.py:1899] - SELECT messages.id, messages.app_id, messages.model_provider, messages.model_id, messages.override_model_configs, messages.conversation_id, messages.inputs, messages.query, messages.message, messages.message_tokens, messages.message_unit_price, messages.message_price_unit, messages.answer, messages.answer_tokens, messages.answer_unit_price, messages.answer_price_unit, messages.provider_response_latency, messages.total_price, messages.currency, messages.status, messages.error, messages.message_metadata, messages.invoke_from, messages.from_source, messages.from_end_user_id, messages.from_account_id, messages.created_at, messages.updated_at, messages.agent_based, messages.workflow_run_id FROM messages WHERE messages.id = %(pk_1)s::UUID 2024-09-06 06:54:03,127.127 INFO [Thread-7 (process_request_thread)] [base.py:1904] - [generated in 0.00065s] {'pk_1': 'd82e1e05-f371-4ded-8846-2203c3a04511'} 2024-09-06 06:54:03,407.407 INFO [Thread-7 (process_request_thread)] [base.py:1899] - SELECT workflows.id AS workflows_id, workflows.tenant_id AS workflows_tenant_id, workflows.app_id AS workflows_app_id, workflows.type AS workflows_type, workflows.version AS workflows_version, workflows.graph AS workflows_graph, workflows.features AS workflows_features, workflows.created_by AS workflows_created_by, workflows.created_at AS workflows_created_at, workflows.updated_by AS workflows_updated_by, workflows.updated_at AS workflows_updated_at, workflows.environment_variables AS workflows_environment_variables, workflows.conversation_variables AS workflows_conversation_variables FROM workflows WHERE workflows.id = %(pk_1)s::UUID 2024-09-06 06:54:03,408.408 INFO [Thread-7 (process_request_thread)] [base.py:1904] - [generated in 0.00101s] {'pk_1': 'cbb9778e-c954-4167-9d21-707c1c46994a'} 2024-09-06 06:54:03,752.752 INFO [Thread-7 (process_request_thread)] [base.py:1899] - SELECT conversations.id AS conversations_id, conversations.app_id AS conversations_app_id, conversations.app_model_config_id AS conversations_app_model_config_id, conversations.model_provider AS conversations_model_provider, conversations.model_id AS conversations_model_id, conversations.mode AS conversations_mode, conversations.name AS conversations_name, conversations.summary AS conversations_summary, conversations.inputs AS conversations_inputs, conversations.introduction AS conversations_introduction, conversations.system_instruction AS conversations_system_instruction, conversations.system_instruction_tokens AS conversations_system_instruction_tokens, conversations.status AS conversations_status, conversations.invoke_from AS conversations_invoke_from, conversations.from_source AS conversations_from_source, conversations.from_end_user_id AS conversations_from_end_user_id, conversations.from_account_id AS conversations_from_account_id, conversations.read_at AS conversations_read_at, conversations.read_account_id AS conversations_read_account_id, conversations.dialogue_count AS conversations_dialogue_count, conversations.created_at AS conversations_created_at, conversations.updated_at AS conversations_updated_at, conversations.is_deleted AS conversations_is_deleted FROM conversations WHERE conversations.id = %(pk_1)s::UUID 2024-09-06 06:54:03,752.752 INFO [Thread-7 (process_request_thread)] [base.py:1904] - [generated in 0.00055s] {'pk_1': '3cc266cf-398e-4485-8b44-0763802a7ee5'} 2024-09-06 06:54:03,887.887 INFO [Thread-7 (process_request_thread)] [base.py:1899] - UPDATE conversations SET override_model_configs=%(override_model_configs)s WHERE conversations.id = %(conversations_id)s::UUID 2024-09-06 06:54:03,887.887 INFO [Thread-7 (process_request_thread)] [base.py:1904] - [generated in 0.00057s] {'override_model_configs': '{"opening_statement": "", "suggested_questions": [], "suggested_questions_after_answer": {"enabled": false}, "text_to_speech": {"enabled": false, "la ... (120 characters truncated) ... d_avoidance": {"enabled": false}, "file_upload": {"image": {"enabled": false, "number_limits": 3, "transfer_methods": ["local_file", "remote_url"]}}}', 'conversations_id': '3cc266cf-398e-4485-8b44-0763802a7ee5'} 2024-09-06 06:54:04,028.028 INFO [Thread-7 (process_request_thread)] [base.py:1142] - COMMIT 2024-09-06 06:54:04,172.172 INFO [Thread-7 (process_request_thread)] [base.py:1099] - BEGIN (implicit) 2024-09-06 06:54:04,175.175 INFO [Thread-7 (process_request_thread)] [base.py:1899] - SELECT conversations.id AS conversations_id, conversations.app_id AS conversations_app_id, conversations.app_model_config_id AS conversations_app_model_config_id, conversations.model_provider AS conversations_model_provider, conversations.override_model_configs AS conversations_override_model_configs, conversations.model_id AS conversations_model_id, conversations.mode AS conversations_mode, conversations.name AS conversations_name, conversations.summary AS conversations_summary, conversations.inputs AS conversations_inputs, conversations.introduction AS conversations_introduction, conversations.system_instruction AS conversations_system_instruction, conversations.system_instruction_tokens AS conversations_system_instruction_tokens, conversations.status AS conversations_status, conversations.invoke_from AS conversations_invoke_from, conversations.from_source AS conversations_from_source, conversations.from_end_user_id AS conversations_from_end_user_id, conversations.from_account_id AS conversations_from_account_id, conversations.read_at AS conversations_read_at, conversations.read_account_id AS conversations_read_account_id, conversations.dialogue_count AS conversations_dialogue_count, conversations.created_at AS conversations_created_at, conversations.updated_at AS conversations_updated_at, conversations.is_deleted AS conversations_is_deleted FROM conversations WHERE conversations.id = %(pk_1)s::UUID 2024-09-06 06:54:04,175.175 INFO [Thread-7 (process_request_thread)] [base.py:1904] - [generated in 0.00044s] {'pk_1': '3cc266cf-398e-4485-8b44-0763802a7ee5'} 2024-09-06 06:54:04,488.488 INFO [Thread-7 (process_request_thread)] [base.py:1899] - SELECT messages.id AS messages_id, messages.app_id AS messages_app_id, messages.model_provider AS messages_model_provider, messages.model_id AS messages_model_id, messages.override_model_configs AS messages_override_model_configs, messages.conversation_id AS messages_conversation_id, messages.inputs AS messages_inputs, messages.query AS messages_query, messages.message AS messages_message, messages.message_tokens AS messages_message_tokens, messages.message_unit_price AS messages_message_unit_price, messages.message_price_unit AS messages_message_price_unit, messages.answer AS messages_answer, messages.answer_tokens AS messages_answer_tokens, messages.answer_unit_price AS messages_answer_unit_price, messages.answer_price_unit AS messages_answer_price_unit, messages.provider_response_latency AS messages_provider_response_latency, messages.total_price AS messages_total_price, messages.currency AS messages_currency, messages.status AS messages_status, messages.error AS messages_error, messages.message_metadata AS messages_message_metadata, messages.invoke_from AS messages_invoke_from, messages.from_source AS messages_from_source, messages.from_end_user_id AS messages_from_end_user_id, messages.from_account_id AS messages_from_account_id, messages.created_at AS messages_created_at, messages.updated_at AS messages_updated_at, messages.agent_based AS messages_agent_based, messages.workflow_run_id AS messages_workflow_run_id FROM messages WHERE messages.id = %(pk_1)s::UUID 2024-09-06 06:54:04,488.488 INFO [Thread-7 (process_request_thread)] [base.py:1904] - [generated in 0.00046s] {'pk_1': 'd82e1e05-f371-4ded-8846-2203c3a04511'} 2024-09-06 06:54:04,624.624 ERROR [Thread-7 (process_request_thread)] [completion.py:143] - internal server error. Traceback (most recent call last): File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/.venv/lib/python3.10/site-packages/redis/connection.py", line 277, in connect sock = self.retry.call_with_retry( File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/.venv/lib/python3.10/site-packages/redis/retry.py", line 62, in call_with_retry return do() File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/.venv/lib/python3.10/site-packages/redis/connection.py", line 278, in <lambda> lambda: self._connect(), lambda error: self.disconnect(error) File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/.venv/lib/python3.10/site-packages/redis/connection.py", line 639, in _connect raise err File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/.venv/lib/python3.10/site-packages/redis/connection.py", line 627, in _connect sock.connect(socket_address) ConnectionRefusedError: [Errno 61] Connection refused During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/controllers/service_api/app/completion.py", line 116, in post response = AppGenerateService.generate( File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/services/app_generate_service.py", line 65, in generate return rate_limit.generate(AdvancedChatAppGenerator().generate( File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/core/app/apps/advanced_chat/app_generator.py", line 123, in generate return self._generate( File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/core/app/apps/advanced_chat/app_generator.py", line 222, in _generate queue_manager = MessageBasedAppQueueManager( File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/core/app/apps/message_based_app_queue_manager.py", line 22, in __init__ super().__init__(task_id, user_id, invoke_from) File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/core/app/apps/base_app_queue_manager.py", line 38, in __init__ redis_client.setex(AppQueueManager._generate_task_belong_cache_key(self._task_id), 1800, File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/.venv/lib/python3.10/site-packages/redis/commands/core.py", line 2358, in setex return self.execute_command("SETEX", name, time, value) File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/.venv/lib/python3.10/site-packages/redis/client.py", line 545, in execute_command conn = self.connection or pool.get_connection(command_name, **options) File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/.venv/lib/python3.10/site-packages/redis/connection.py", line 1074, in get_connection connection.connect() File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/.venv/lib/python3.10/site-packages/redis/connection.py", line 283, in connect raise ConnectionError(self._error_message(e)) redis.exceptions.ConnectionError: Error 61 connecting to localhost:6379. Connection refused. 2024-09-06 06:54:04,635.635 ERROR [Thread-7 (process_request_thread)] [app.py:838] - Exception on /v1/chat-messages [POST] Traceback (most recent call last): File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/.venv/lib/python3.10/site-packages/redis/connection.py", line 277, in connect sock = self.retry.call_with_retry( File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/.venv/lib/python3.10/site-packages/redis/retry.py", line 62, in call_with_retry return do() File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/.venv/lib/python3.10/site-packages/redis/connection.py", line 278, in <lambda> lambda: self._connect(), lambda error: self.disconnect(error) File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/.venv/lib/python3.10/site-packages/redis/connection.py", line 639, in _connect raise err File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/.venv/lib/python3.10/site-packages/redis/connection.py", line 627, in _connect sock.connect(socket_address) ConnectionRefusedError: [Errno 61] Connection refused During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/controllers/service_api/app/completion.py", line 116, in post response = AppGenerateService.generate( File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/services/app_generate_service.py", line 65, in generate return rate_limit.generate(AdvancedChatAppGenerator().generate( File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/core/app/apps/advanced_chat/app_generator.py", line 123, in generate return self._generate( File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/core/app/apps/advanced_chat/app_generator.py", line 222, in _generate queue_manager = MessageBasedAppQueueManager( File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/core/app/apps/message_based_app_queue_manager.py", line 22, in __init__ super().__init__(task_id, user_id, invoke_from) File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/core/app/apps/base_app_queue_manager.py", line 38, in __init__ redis_client.setex(AppQueueManager._generate_task_belong_cache_key(self._task_id), 1800, File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/.venv/lib/python3.10/site-packages/redis/commands/core.py", line 2358, in setex return self.execute_command("SETEX", name, time, value) File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/.venv/lib/python3.10/site-packages/redis/client.py", line 545, in execute_command conn = self.connection or pool.get_connection(command_name, **options) File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/.venv/lib/python3.10/site-packages/redis/connection.py", line 1074, in get_connection connection.connect() File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/.venv/lib/python3.10/site-packages/redis/connection.py", line 283, in connect raise ConnectionError(self._error_message(e)) redis.exceptions.ConnectionError: Error 61 connecting to localhost:6379. Connection refused. During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/.venv/lib/python3.10/site-packages/flask/app.py", line 880, in full_dispatch_request rv = self.dispatch_request() File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/.venv/lib/python3.10/site-packages/flask/app.py", line 865, in dispatch_request return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return] File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/.venv/lib/python3.10/site-packages/flask_restful/__init__.py", line 489, in wrapper resp = resource(*args, **kwargs) File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/.venv/lib/python3.10/site-packages/flask/views.py", line 110, in view return current_app.ensure_sync(self.dispatch_request)(**kwargs) # type: ignore[no-any-return] File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/.venv/lib/python3.10/site-packages/flask_restful/__init__.py", line 604, in dispatch_request resp = meth(*args, **kwargs) File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/controllers/service_api/wraps.py", line 75, in decorated_view return view_func(*args, **kwargs) File "/Users/duncanchang/Desktop/lang/dev_dify_2/api/controllers/service_api/app/completion.py", line 144, in post raise InternalServerError() werkzeug.exceptions.InternalServerError: 500 Internal Server Error: The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application. 2024-09-06 06:54:04,637.637 INFO [Thread-7 (process_request_thread)] [base.py:1125] - ROLLBACK 2024-09-06 06:54:04,771.771 INFO [Thread-7 (process_request_thread)] [_internal.py:97] - 127.0.0.1 - - [06/Sep/2024 06:54:04] "POST /v1/chat-messages HTTP/1.1" 500 - ``` ### ✔️ Expected Behavior it should return my normal message ### ❌ Actual Behavior { "code": "internal_server_error", "message": "The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.", "status": 500 }
yindo added the 🐞 bug🤔 cant-reproduce labels 2026-02-21 18:11:16 -05:00
yindo closed this issue 2026-02-21 18:11:17 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Sep 9, 2024):

The internal server error you're encountering when using the OpenAPI of the chatbot's chatflow in Dify version 0.7.1 is likely due to a ConnectionRefusedError with Redis. This error indicates that the application is unable to connect to the Redis server.

Here are some common causes and troubleshooting steps:

  1. Redis Service Not Running: Ensure that the Redis service is running. You can check the status of the Redis container using Docker commands:

    docker-compose ps redis
    
  2. Verify Redis Host and Port: Ensure that the REDIS_HOST and REDIS_PORT environment variables are correctly set in your docker-compose.yaml file:

    REDIS_HOST: redis
    REDIS_PORT: 6379
    
  3. Check Network Connectivity: Ensure that the application can reach the Redis server. You can use tools like ping or telnet to verify connectivity:

    ping redis
    telnet redis 6379
    
  4. Verify Authentication Credentials: Ensure that the REDIS_PASSWORD is correctly set and matches the password configured in the Redis server:

    REDIS_PASSWORD: difyai123456
    
  5. Check Firewall and Security Groups: Ensure that there are no firewall rules or security groups blocking the connection to the Redis server.

  6. Review Docker Logs: Check the logs of the Redis container for any errors or issues:

    docker-compose logs redis
    
  7. Review Redis Configuration: Ensure that other Redis-related environment variables are correctly set, such as REDIS_DB, REDIS_USERNAME, REDIS_USE_SSL, and REDIS_USE_SENTINEL if applicable. For example:

    REDIS_DB: 0
    REDIS_USERNAME: ''
    REDIS_USE_SSL: 'false'
    REDIS_USE_SENTINEL: 'false'
    
  8. Check Docker Network Configuration: If you are using Docker to deploy Dify and Redis, ensure that the network configuration allows the containers to communicate. For example, if you encounter issues with localhost, you might need to use host.docker.internal to refer to the host machine from within a Docker container:

    REDIS_HOST: host.docker.internal
    

By following these steps, you should be able to identify and resolve the ConnectionRefusedError related to Redis in the Dify application [1][2].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Sep 9, 2024): <!-- Answer --> The internal server error you're encountering when using the OpenAPI of the chatbot's chatflow in Dify version 0.7.1 is likely due to a `ConnectionRefusedError` with Redis. This error indicates that the application is unable to connect to the Redis server. Here are some common causes and troubleshooting steps: 1. **Redis Service Not Running**: Ensure that the Redis service is running. You can check the status of the Redis container using Docker commands: ```sh docker-compose ps redis ``` 2. **Verify Redis Host and Port**: Ensure that the `REDIS_HOST` and `REDIS_PORT` environment variables are correctly set in your `docker-compose.yaml` file: ```yaml REDIS_HOST: redis REDIS_PORT: 6379 ``` 3. **Check Network Connectivity**: Ensure that the application can reach the Redis server. You can use tools like `ping` or `telnet` to verify connectivity: ```sh ping redis telnet redis 6379 ``` 4. **Verify Authentication Credentials**: Ensure that the `REDIS_PASSWORD` is correctly set and matches the password configured in the Redis server: ```yaml REDIS_PASSWORD: difyai123456 ``` 5. **Check Firewall and Security Groups**: Ensure that there are no firewall rules or security groups blocking the connection to the Redis server. 6. **Review Docker Logs**: Check the logs of the Redis container for any errors or issues: ```sh docker-compose logs redis ``` 7. **Review Redis Configuration**: Ensure that other Redis-related environment variables are correctly set, such as `REDIS_DB`, `REDIS_USERNAME`, `REDIS_USE_SSL`, and `REDIS_USE_SENTINEL` if applicable. For example: ```yaml REDIS_DB: 0 REDIS_USERNAME: '' REDIS_USE_SSL: 'false' REDIS_USE_SENTINEL: 'false' ``` 8. **Check Docker Network Configuration**: If you are using Docker to deploy Dify and Redis, ensure that the network configuration allows the containers to communicate. For example, if you encounter issues with `localhost`, you might need to use `host.docker.internal` to refer to the host machine from within a Docker container: ```yaml REDIS_HOST: host.docker.internal ``` By following these steps, you should be able to identify and resolve the `ConnectionRefusedError` related to Redis in the Dify application <sup>[[1]](https://github.com/langgenius/dify/blob/main/docker/docker-compose.yaml)</sup><sup>[[2]](https://github.com/langgenius/dify-docs/blob/main/zh_CN/getting-started/install-self-hosted/environments.md)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@crazywoola commented on GitHub (Sep 9, 2024):

Tested in v0.7.3, please upgrade to the latest version to see if this issue persists. Also please check the env settings as well in .env.

data: {"event": "workflow_finished", "conversation_id": "a75577e2-d086-4874-8d81-a146332d3c50", "message_id": "ef4fecc7-1a70-440e-a98c-752e5ebc3f9c", "created_at": 1725938614, "task_id": "6a4fcf62-482a-4f73-9248-b4d50c80f736", "workflow_run_id": "f2b63ba2-b301-4d7c-9ea0-eed30654d28f", "data": {"id": "f2b63ba2-b301-4d7c-9ea0-eed30654d28f", "workflow_id": "f0f37892-684b-4cc4-8c0a-0f567fc53cd2", "sequence_number": 3, "status": "succeeded", "outputs": {"answer": "Here are the specs of the iPhone 13 Pro Max:\n\n- Display: 6.7-inch Super Retina XDR OLED, 120Hz ProMotion\n- Resolution: 2796 x 1290 pixels\n- Camera: 12MP ultra-wide, 12MP wide, and 12MP telephoto rear cameras; 12MP TrueDepth front camera\n- Processor: Apple A15 Bionic chip\n- Storage: 128GB, 256GB, 512GB, or 1TB\n- Battery: Up to 29 hours of video playback\n- Connectivity: 5G, Wi-Fi 6, Bluetooth 5.0\n- Size: 150.7 x 76.7 x 7.65mm\n- Weight: 238g\n\nPlease note that these specs are subject to change and may vary depending on the source."}, "error": null, "elapsed_time": 4.745936965002329, "total_tokens": 176, "total_steps": 3, "created_by": {"id": "df74ac8a-ad9f-4e4b-b166-fa194f05aea1", "user": "abc-123"}, "created_at": 1725938614, "finished_at": 1725938618, "files": []}}

data: {"event": "message_end", "conversation_id": "a75577e2-d086-4874-8d81-a146332d3c50", "message_id": "ef4fecc7-1a70-440e-a98c-752e5ebc3f9c", "created_at": 1725938614, "task_id": "6a4fcf62-482a-4f73-9248-b4d50c80f736", "id": "ef4fecc7-1a70-440e-a98c-752e5ebc3f9c", "metadata": {"usage": {"prompt_tokens": 11, "prompt_unit_price": "0.005", "prompt_price_unit": "0.001", "prompt_price": "0.0000550", "completion_tokens": 165, "completion_unit_price": "0.020", "completion_price_unit": "0.001", "completion_price": "0.0033000", "total_tokens": 176, "total_price": "0.0033550", "currency": "RMB", "latency": 4.731395859998884}}}

data: {"event": "tts_message_end", "conversation_id": "a75577e2-d086-4874-8d81-a146332d3c50", "message_id": "ef4fecc7-1a70-440e-a98c-752e5ebc3f9c", "created_at": 1725938614, "task_id": "6a4fcf62-482a-4f73-9248-b4d50c80f736", "audio": ""}
@crazywoola commented on GitHub (Sep 9, 2024): Tested in v0.7.3, please upgrade to the latest version to see if this issue persists. Also please check the env settings as well in `.env`. ``` data: {"event": "workflow_finished", "conversation_id": "a75577e2-d086-4874-8d81-a146332d3c50", "message_id": "ef4fecc7-1a70-440e-a98c-752e5ebc3f9c", "created_at": 1725938614, "task_id": "6a4fcf62-482a-4f73-9248-b4d50c80f736", "workflow_run_id": "f2b63ba2-b301-4d7c-9ea0-eed30654d28f", "data": {"id": "f2b63ba2-b301-4d7c-9ea0-eed30654d28f", "workflow_id": "f0f37892-684b-4cc4-8c0a-0f567fc53cd2", "sequence_number": 3, "status": "succeeded", "outputs": {"answer": "Here are the specs of the iPhone 13 Pro Max:\n\n- Display: 6.7-inch Super Retina XDR OLED, 120Hz ProMotion\n- Resolution: 2796 x 1290 pixels\n- Camera: 12MP ultra-wide, 12MP wide, and 12MP telephoto rear cameras; 12MP TrueDepth front camera\n- Processor: Apple A15 Bionic chip\n- Storage: 128GB, 256GB, 512GB, or 1TB\n- Battery: Up to 29 hours of video playback\n- Connectivity: 5G, Wi-Fi 6, Bluetooth 5.0\n- Size: 150.7 x 76.7 x 7.65mm\n- Weight: 238g\n\nPlease note that these specs are subject to change and may vary depending on the source."}, "error": null, "elapsed_time": 4.745936965002329, "total_tokens": 176, "total_steps": 3, "created_by": {"id": "df74ac8a-ad9f-4e4b-b166-fa194f05aea1", "user": "abc-123"}, "created_at": 1725938614, "finished_at": 1725938618, "files": []}} data: {"event": "message_end", "conversation_id": "a75577e2-d086-4874-8d81-a146332d3c50", "message_id": "ef4fecc7-1a70-440e-a98c-752e5ebc3f9c", "created_at": 1725938614, "task_id": "6a4fcf62-482a-4f73-9248-b4d50c80f736", "id": "ef4fecc7-1a70-440e-a98c-752e5ebc3f9c", "metadata": {"usage": {"prompt_tokens": 11, "prompt_unit_price": "0.005", "prompt_price_unit": "0.001", "prompt_price": "0.0000550", "completion_tokens": 165, "completion_unit_price": "0.020", "completion_price_unit": "0.001", "completion_price": "0.0033000", "total_tokens": 176, "total_price": "0.0033550", "currency": "RMB", "latency": 4.731395859998884}}} data: {"event": "tts_message_end", "conversation_id": "a75577e2-d086-4874-8d81-a146332d3c50", "message_id": "ef4fecc7-1a70-440e-a98c-752e5ebc3f9c", "created_at": 1725938614, "task_id": "6a4fcf62-482a-4f73-9248-b4d50c80f736", "audio": ""} ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#5498