Skip to content

Connection Error #1

@Firegolden

Description

@Firegolden

用的是deepseek模型。deepsek的链接密钥这些确定没有问题,都试过了。
Client端输入问题后,返回如下错误:
Simplified request error: Connection error.
Error: cannot access local variable 'completion' where it is not associated with a value

能够基础判断是以下这段发生的:
completion = await self.openai.chat.completions.create(
model=os.getenv("OPENAI_MODEL"),
max_tokens=1000,
messages=messages,
tools=available_tools
)

代理问题,这个不清楚,但是设置代理后 启动服务就报错。

  • Exception Group Traceback (most recent call last):
    | File "C:\Workbooks\ple\mcp_client\client.py", line 289, in main
    | await client.connect_to_sse_server(server_url=sys.argv[1])
    | File "C:\Workbooks\ple\mcp_client\client.py", line 159, in connect_to_sse_server
    | streams = await self._streams_context.aenter()
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "C:\Users\user\AppData\Local\Programs\Python\Python313\Lib\contextlib.py", line 214, in aenter
    | return await anext(self.gen)
    | ^^^^^^^^^^^^^^^^^^^^^
    | File "C:\Workbooks\ple\mcp_client.venv\Lib\site-packages\mcp\client\sse.py", line 43, in sse_client
    | async with anyio.create_task_group() as tg:
    | ~~~~~~~~~~~~~~~~~~~~~~~^^
    | File "C:\Workbooks\ple\mcp_client.venv\Lib\site-packages\anyio_backends_asyncio.py", line 772, in aexit
    | raise BaseExceptionGroup(
    | "unhandled errors in a TaskGroup", self._exceptions
    | ) from None
    | ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
    +-+---------------- 1 ----------------
    | Traceback (most recent call last):
    | File "C:\Workbooks\ple\mcp_client.venv\Lib\site-packages\mcp\client\sse.py", line 53, in sse_client
    | event_source.response.raise_for_status()
    | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
    | File "C:\Workbooks\ple\mcp_client.venv\Lib\site-packages\httpx_models.py", line 829, in raise_for_status
    | raise HTTPStatusError(message, request=request, response=self)
    | httpx.HTTPStatusError: Client error '403 Target service not allowed' for url 'http://111.139.23:8020/sse'
    | For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/403
    +------------------------------------

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Workbooks\ple\mcp_client\client.py", line 297, in
asyncio.run(main())
~~~~~~~~~~~^^^^^^^^
File "C:\Users\user\AppData\Local\Programs\Python\Python313\Lib\asyncio\runners.py", line 194, in run
return runner.run(main)
~~~~~~~~~~^^^^^^
File "C:\Users\user\AppData\Local\Programs\Python\Python313\Lib\asyncio\runners.py", line 118, in run
return self._loop.run_until_complete(task)
File "C:\Users\user\AppData\Local\Programs\Python\Python313\Lib\asyncio\base_events.py", line 720, in run_until_complete
return future.result()
~~~~~~~~~~~~~^^
File "C:\Workbooks\ple\mcp_client\client.py", line 292, in main
await client.cleanup()
File "C:\Workbooks\ple\mcp_client\client.py", line 176, in cleanup
if self._session_context:
^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'MCPClient' object has no attribute '_session_context'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions