Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[远程部署]: 界面打开后显示Connection errored out #1161

Closed
2 tasks done
peilongchencc opened this issue Sep 14, 2024 · 7 comments
Closed
2 tasks done

[远程部署]: 界面打开后显示Connection errored out #1161

peilongchencc opened this issue Sep 14, 2024 · 7 comments
Labels
question Further information is requested server deployment 在远程服务器上部署的问题

Comments

@peilongchencc
Copy link

是否已存在现有反馈与解答?

  • 我确认没有已有issue或discussion,且已阅读常见问题

是否是一个代理配置相关的疑问?

  • 我确认这不是一个代理配置相关的疑问。

错误描述

终端 python ChuanhuChatbot.py 启动服务后,界面报错:

image

复现操作

我的操作如下:

  1. 拉取项目(2024年9月13日拉取)
git clone https://github.com/GaiZhenbiao/ChuanhuChatGPT.git
cd ChuanhuChatGPT
  1. 创建虚拟环境、安装依赖项:
conda create -n chuanhu python=3.10
conda activate chuanhu
pip install -r requirements.txt
  1. 配置 config.json,我的内容如下:

我已尝试,如果设置登录账号和密码,进入主页也会显示相同错误。

{
    "openai_api_key": "sk-xxxxxxxxx",
    "language": "auto",
    "users": [],

    "https_proxy": "http://127.0.0.1:7890",
    "http_proxy": "http://127.0.0.1:7890",

    "server_name": "0.0.0.0",
    "server_port": 7860,
    "share": false
}
  1. 启动服务:
python ChuanhuChatbot.py

稍作等待,浏览器自动打开 http://localhost:7860/ ,但提示 Connection errored out

错误日志

(chuanhu) root@iZ2zea5v77oawjy2qz7c20Z:/data/ChuanhuChatGPT# python ChuanhuChatbot.py 
2024-09-14 11:58:59,013 [INFO] [_client.py:1038] HTTP Request: GET https://api.gradio.app/gradio-messaging/en "HTTP/1.1 200 OK"
2024-09-14 11:58:59,427 [INFO] [config.py:330] 默认模型设置为了:GPT-4o-mini
2024-09-14 11:59:00,160 [INFO] [utils.py:161] NumExpr defaulting to 4 threads.
Running on local URL:  http://0.0.0.0:7860

To create a public link, set `share=True` in `launch()`.
2024-09-14 11:59:01,285 [INFO] [utils.py:643] Your IP region: Japan。
IMPORTANT: You are using gradio version 4.26.0, however version 4.29.0 is available, please upgrade.
--------
ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/pydantic/type_adapter.py", line 190, in __init__
    core_schema = _getattr_no_parents(type, '__pydantic_core_schema__')
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/pydantic/type_adapter.py", line 98, in _getattr_no_parents
    raise AttributeError(attribute)
AttributeError: __pydantic_core_schema__

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/uvicorn/protocols/http/h11_impl.py", line 406, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 70, in __call__
    return await self.app(scope, receive, send)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/fastapi/applications.py", line 1054, in __call__
    await super().__call__(scope, receive, send)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/starlette/applications.py", line 113, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/starlette/middleware/errors.py", line 187, in __call__
    raise exc
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/starlette/middleware/errors.py", line 165, in __call__
    await self.app(scope, receive, _send)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/gradio/route_utils.py", line 695, in __call__
    await self.simple_response(scope, receive, send, request_headers=headers)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/gradio/route_utils.py", line 711, in simple_response
    await self.app(scope, receive, send)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 62, in __call__
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/starlette/_exception_handler.py", line 62, in wrapped_app
    raise exc
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/starlette/_exception_handler.py", line 51, in wrapped_app
    await app(scope, receive, sender)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/starlette/routing.py", line 715, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/starlette/routing.py", line 735, in app
    await route.handle(scope, receive, send)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/starlette/routing.py", line 288, in handle
    await self.app(scope, receive, send)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/starlette/routing.py", line 76, in app
    await wrap_app_handling_exceptions(app, request)(scope, receive, send)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/starlette/_exception_handler.py", line 62, in wrapped_app
    raise exc
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/starlette/_exception_handler.py", line 51, in wrapped_app
    await app(scope, receive, sender)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/starlette/routing.py", line 73, in app
    response = await f(request)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/fastapi/routing.py", line 291, in app
    solved_result = await solve_dependencies(
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/fastapi/dependencies/utils.py", line 639, in solve_dependencies
    ) = await request_body_to_args(  # body_params checked above
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/fastapi/dependencies/utils.py", line 813, in request_body_to_args
    fields_to_extract = get_cached_model_fields(first_field.type_)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/fastapi/_compat.py", line 657, in get_cached_model_fields
    return get_model_fields(model)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/fastapi/_compat.py", line 284, in get_model_fields
    return [
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/fastapi/_compat.py", line 285, in <listcomp>
    ModelField(field_info=field_info, name=name)
  File "<string>", line 6, in __init__
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/fastapi/_compat.py", line 110, in __post_init__
    self._type_adapter: TypeAdapter[Any] = TypeAdapter(
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/pydantic/type_adapter.py", line 192, in __init__
    core_schema = _get_schema(type, config_wrapper, parent_depth=_parent_depth + 1)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/pydantic/type_adapter.py", line 81, in _get_schema
    schema = gen.generate_schema(type_)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 468, in generate_schema
    schema = self._generate_schema(obj)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 700, in _generate_schema
    schema = self._post_process_generated_schema(self._generate_schema_inner(obj))
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 707, in _generate_schema_inner
    return self._annotated_schema(obj)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 1586, in _annotated_schema
    schema = self._apply_annotations(source_type, annotations)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 1654, in _apply_annotations
    schema = get_inner_schema(source_type)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/pydantic/_internal/_schema_generation_shared.py", line 82, in __call__
    schema = self._handler(__source_type)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 1736, in new_handler
    schema = metadata_get_schema(source, get_inner_schema)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 1732, in <lambda>
    lambda source, handler: handler(source)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/pydantic/_internal/_schema_generation_shared.py", line 82, in __call__
    schema = self._handler(__source_type)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 1635, in inner_handler
    schema = self._generate_schema(obj)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 700, in _generate_schema
    schema = self._post_process_generated_schema(self._generate_schema_inner(obj))
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 727, in _generate_schema_inner
    return self.match_type(obj)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 810, in match_type
    return self._match_generic_type(obj, origin)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 834, in _match_generic_type
    return self._union_schema(obj)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 1036, in _union_schema
    choices.append(self.generate_schema(arg))
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 468, in generate_schema
    schema = self._generate_schema(obj)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 700, in _generate_schema
    schema = self._post_process_generated_schema(self._generate_schema_inner(obj))
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 727, in _generate_schema_inner
    return self.match_type(obj)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 814, in match_type
    return self._unknown_type_schema(obj)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 366, in _unknown_type_schema
    raise PydanticSchemaGenerationError(
pydantic.errors.PydanticSchemaGenerationError: Unable to generate pydantic-core schema for <class 'starlette.requests.Request'>. Set `arbitrary_types_allowed=True` in the model_config to ignore this error or implement `__get_pydantic_core_schema__` on your type to fully support it.

If you got this error by calling handler(<some type>) within `__get_pydantic_core_schema__` then you likely need to call `handler.generate_schema(<some type>)` since we do not call `__get_pydantic_core_schema__` on `<some type>` otherwise to avoid infinite recursion.

For further information visit https://errors.pydantic.dev/2.5/u/schema-for-unknown-type
ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/pydantic/type_adapter.py", line 190, in __init__
    core_schema = _getattr_no_parents(type, '__pydantic_core_schema__')
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/pydantic/type_adapter.py", line 98, in _getattr_no_parents
    raise AttributeError(attribute)
AttributeError: __pydantic_core_schema__

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/uvicorn/protocols/http/h11_impl.py", line 406, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 70, in __call__
    return await self.app(scope, receive, send)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/fastapi/applications.py", line 1054, in __call__
    await super().__call__(scope, receive, send)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/starlette/applications.py", line 113, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/starlette/middleware/errors.py", line 187, in __call__
    raise exc
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/starlette/middleware/errors.py", line 165, in __call__
    await self.app(scope, receive, _send)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/gradio/route_utils.py", line 695, in __call__
    await self.simple_response(scope, receive, send, request_headers=headers)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/gradio/route_utils.py", line 711, in simple_response
    await self.app(scope, receive, send)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 62, in __call__
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/starlette/_exception_handler.py", line 62, in wrapped_app
    raise exc
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/starlette/_exception_handler.py", line 51, in wrapped_app
    await app(scope, receive, sender)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/starlette/routing.py", line 715, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/starlette/routing.py", line 735, in app
    await route.handle(scope, receive, send)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/starlette/routing.py", line 288, in handle
    await self.app(scope, receive, send)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/starlette/routing.py", line 76, in app
    await wrap_app_handling_exceptions(app, request)(scope, receive, send)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/starlette/_exception_handler.py", line 62, in wrapped_app
    raise exc
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/starlette/_exception_handler.py", line 51, in wrapped_app
    await app(scope, receive, sender)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/starlette/routing.py", line 73, in app
    response = await f(request)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/fastapi/routing.py", line 291, in app
    solved_result = await solve_dependencies(
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/fastapi/dependencies/utils.py", line 639, in solve_dependencies
    ) = await request_body_to_args(  # body_params checked above
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/fastapi/dependencies/utils.py", line 813, in request_body_to_args
    fields_to_extract = get_cached_model_fields(first_field.type_)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/fastapi/_compat.py", line 657, in get_cached_model_fields
    return get_model_fields(model)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/fastapi/_compat.py", line 284, in get_model_fields
    return [
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/fastapi/_compat.py", line 285, in <listcomp>
    ModelField(field_info=field_info, name=name)
  File "<string>", line 6, in __init__
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/fastapi/_compat.py", line 110, in __post_init__
    self._type_adapter: TypeAdapter[Any] = TypeAdapter(
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/pydantic/type_adapter.py", line 192, in __init__
    core_schema = _get_schema(type, config_wrapper, parent_depth=_parent_depth + 1)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/pydantic/type_adapter.py", line 81, in _get_schema
    schema = gen.generate_schema(type_)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 468, in generate_schema
    schema = self._generate_schema(obj)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 700, in _generate_schema
    schema = self._post_process_generated_schema(self._generate_schema_inner(obj))
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 707, in _generate_schema_inner
    return self._annotated_schema(obj)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 1586, in _annotated_schema
    schema = self._apply_annotations(source_type, annotations)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 1654, in _apply_annotations
    schema = get_inner_schema(source_type)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/pydantic/_internal/_schema_generation_shared.py", line 82, in __call__
    schema = self._handler(__source_type)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 1736, in new_handler
    schema = metadata_get_schema(source, get_inner_schema)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 1732, in <lambda>
    lambda source, handler: handler(source)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/pydantic/_internal/_schema_generation_shared.py", line 82, in __call__
    schema = self._handler(__source_type)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 1635, in inner_handler
    schema = self._generate_schema(obj)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 700, in _generate_schema
    schema = self._post_process_generated_schema(self._generate_schema_inner(obj))
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 727, in _generate_schema_inner
    return self.match_type(obj)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 810, in match_type
    return self._match_generic_type(obj, origin)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 834, in _match_generic_type
    return self._union_schema(obj)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 1036, in _union_schema
    choices.append(self.generate_schema(arg))
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 468, in generate_schema
    schema = self._generate_schema(obj)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 700, in _generate_schema
    schema = self._post_process_generated_schema(self._generate_schema_inner(obj))
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 727, in _generate_schema_inner
    return self.match_type(obj)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 814, in match_type
    return self._unknown_type_schema(obj)
  File "/root/anaconda3/envs/chuanhu/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 366, in _unknown_type_schema
    raise PydanticSchemaGenerationError(
pydantic.errors.PydanticSchemaGenerationError: Unable to generate pydantic-core schema for <class 'starlette.requests.Request'>. Set `arbitrary_types_allowed=True` in the model_config to ignore this error or implement `__get_pydantic_core_schema__` on your type to fully support it.

If you got this error by calling handler(<some type>) within `__get_pydantic_core_schema__` then you likely need to call `handler.generate_schema(<some type>)` since we do not call `__get_pydantic_core_schema__` on `<some type>` otherwise to avoid infinite recursion.

For further information visit https://errors.pydantic.dev/2.5/u/schema-for-unknown-type

运行环境

  • OS: ubuntu 22.04
  • Server: Alibaba Cloud ubuntu 22.04
  • Gradio version: 4.26.0
  • Python version: 3.10.14
  • Browser: Chrome浏览器

补充说明

我已查看查看疑难杂症解决页面,没有符合我的错误场景。

我已尽可能查看相似issue和disscusion,例如 #89#100#287#309#528,发现与我的错误场景都不同。

个人尝试:

  1. 配置Nginx

配置Nginx后,运行程序,依旧提示相同错误(Connection errored out),终端错误日志相同。

(chuanhu) root@iZ2zea5v77oawjy2qz7c20Z:/data/ChuanhuChatGPT# cat /etc/nginx/sites-available/www.peilongchencc.cn 
server {
    listen 80;  # 监听 80 端口,用于处理 HTTP 请求
    server_name peilongchencc.cn www.peilongchencc.cn;  # 定义服务器的域名,允许通过 peilongchencc.cn 和 www.peilongchencc.cn 访问

    # 将所有 HTTP 请求永久重定向到 HTTPS
    # 301 状态码表示永久重定向,$host 代表请求的主机,$request_uri 代表请求的 URI
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;  # 监听 443 端口,启用 SSL(即 HTTPS)
    server_name peilongchencc.cn www.peilongchencc.cn;  # 定义服务器的域名,允许通过 peilongchencc.cn 和 www.peilongchencc.cn 访问

    # SSL 证书配置,用于加密 HTTPS 连接
    ssl_certificate /etc/letsencrypt/live/www.peilongchencc.cn/fullchain.pem;  # 定义 SSL 证书的完整链路径
    ssl_certificate_key /etc/letsencrypt/live/www.peilongchencc.cn/privkey.pem;  # 定义 SSL 证书的私钥路径

    # 配置 WebSocket 代理
    location / {
        # 将所有请求代理到本地 7860 端口上的应用
        proxy_pass http://localhost:7860;

        # 支持 WebSocket 连接,WebSocket 升级需要设置 HTTP/1.1 协议
        proxy_http_version 1.1;  # 使用 HTTP 1.1 协议支持 WebSocket
        proxy_set_header Upgrade $http_upgrade;  # 设置 Upgrade 头,用于处理 WebSocket 升级
        proxy_set_header Connection "upgrade";  # 将连接类型设置为 "upgrade" 以启用 WebSocket

        # 保留客户端的真实请求信息
        proxy_set_header Host $host;  # 保留客户端的 Host 头信息
        proxy_set_header X-Real-IP $remote_addr;  # 传递客户端的真实 IP 地址
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  # 传递代理链中的客户端 IP 地址
        proxy_set_header X-Forwarded-Proto $scheme;  # 保留客户端的协议(HTTP 或 HTTPS)

        # 防止超时(任何一个时刻超过 60 秒没有数据传输)
        # 如果超过 60 秒没有数据传输,则可能触发超时错误,proxy_read_timeout 和 proxy_send_timeout 用于防止此类问题
        # 以流式输出举例,如果程序一直在输出内容,超过60s也不会报错。
        proxy_read_timeout 60s;  # 允许 Nginx 等待后端服务器的响应,最长不超过 60 秒
        proxy_send_timeout 60s;  # 允许 Nginx 发送数据到后端服务器的时间限制,最长不超过 60 秒
    }
}
(chuanhu) root@iZ2zea5v77oawjy2qz7c20Z:/data/ChuanhuChatGPT# 
  1. 尝试修改服务端口,例如 http://localhost:8866http://localhost:8867 均无效。

  2. 尝试将 pydantic 升级到最新版本,无效。

  3. 尝试将 gradio 升级到最新版本,无效。

Ps: 由于终端已经提示 "Your IP region: Japan。",因此我没有在Clash配置文件中添加常见问题中的配置。

@peilongchencc peilongchencc added question Further information is requested server deployment 在远程服务器上部署的问题 labels Sep 14, 2024
@peilongchencc
Copy link
Author

@GaiZhenbiao
麻烦您有空帮忙看一下

@GaiZhenbiao
Copy link
Owner

请查看wiki中关于服务器部署的部分,你这应该是nginx没有配置websocket导致的。

@Keldos-Li
Copy link
Collaborator

不过这个issue真的提得赏心悦目)

@peilongchencc
Copy link
Author

请查看wiki中关于服务器部署的部分,你这应该是nginx没有配置websocket导致的。

🚨我按照您wiki中关于服务器部署教程,配置并重新载入nginx后。python ChuanhuChatbot.py启动服务,错误是一样的

界面:

image

image

修改后的/etc/nginx/nginx.conf配置如下:

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 768;
    # multi_accept on;
}

http {
    ##
    # Basic Settings
    ##

    # WebSocket connection upgrade configuration
    map $http_upgrade $connection_upgrade {
        default upgrade;
        ''      close;
    }

    sendfile on;
    tcp_nopush on;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # SSL Settings
    ##
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##
    gzip on;

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Virtual Host Configs
    ##
    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

修改后的/etc/nginx/sites-available/www.peilongchencc.cn配置如下:

# HTTP to HTTPS redirect
server {
    listen 80;
    server_name www.peilongchencc.cn;
    return 301 https://$host$request_uri;  # 强制重定向到 HTTPS
}

# HTTPS server block
server {
    listen 443 ssl;
    server_name www.peilongchencc.cn;

    # SSL 证书配置
    ssl_certificate /etc/letsencrypt/live/www.peilongchencc.cn/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/www.peilongchencc.cn/privkey.pem;
    ssl_protocols TLSv1.2 TLSv1.3;

    # 日志配置
    access_log /var/log/nginx/www.peilongchencc.cn.access.log;
    error_log /var/log/nginx/www.peilongchencc.cn.error.log;

    location / {
        proxy_pass http://127.0.0.1:7860;   # 注意端口号
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Upgrade $http_upgrade;   # Websocket配置
        proxy_set_header Connection $connection_upgrade;   # Websocket配置
        proxy_max_temp_file_size 0;
        client_max_body_size 10m;
        client_body_buffer_size 128k;
        proxy_connect_timeout 90;
        proxy_send_timeout 90;
        proxy_read_timeout 90;
        proxy_buffer_size 4k;
        proxy_buffers 4 32k;
        proxy_busy_buffers_size 64k;
        proxy_temp_file_write_size 64k;
    }
}

Nginx语法没有问题,效果如下:

(chuanhu) root@iZ2zea5v77oawjy2qz7c20Z:/data/ChuanhuChatGPT# sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
(chuanhu) root@iZ2zea5v77oawjy2qz7c20Z:/data/ChuanhuChatGPT# sudo systemctl reload nginx
(chuanhu) root@iZ2zea5v77oawjy2qz7c20Z:/data/ChuanhuChatGPT# 

@GaiZhenbiao
Copy link
Owner

看上去应该是一些库的版本问题。你安装下面的版本试试:
pip install openapi-schema-pydantic==1.2.4 pydantic==2.5.2 pydantic-core==2.14.5 fastapi==0.104.1

@GaiZhenbiao GaiZhenbiao reopened this Sep 14, 2024
@peilongchencc
Copy link
Author

看上去应该是一些库的版本问题。你安装下面的版本试试: pip install openapi-schema-pydantic==1.2.4 pydantic==2.5.2 pydantic-core==2.14.5 fastapi==0.104.1

正解!运行成功。效果如下:

image

@HopeCollector
Copy link

看上去应该是一些库的版本问题。你安装下面的版本试试: pip install openapi-schema-pydantic==1.2.4 pydantic==2.5.2 pydantic-core==2.14.5 fastapi==0.104.1

Docker 镜像id :sha256:a970a9127622fdf95a49aaf4b15d97dc06ed7d4d1acf63e7dff6e537d8335b6d
仍然有相同的问题,而且可以用这个方法解决

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested server deployment 在远程服务器上部署的问题
Projects
None yet
Development

No branches or pull requests

4 participants