windows环境下python sdk无法使用

测试最简单的代码也不行。

我的代码

from iflow_sdk import query_sync, IFlowOptions

# 同步调用,带超时控制
options = IFlowOptions(timeout=30.0)
response = query_sync("你好", options=options)
print(response)

报错如下:

INFO:iflow_sdk._internal.transport:Connecting to ws://localhost:8090/acp
INFO:iflow_sdk.client:iFlow not running, starting process...
INFO:iflow_sdk._internal.process_manager:Starting iFlow process: C:\Program Files\nodejs\iflow.CMD --experimental-acp --port 8090
INFO:iflow_sdk._internal.process_manager:iFlow process started on port 8090 (PID: 49760)
INFO:iflow_sdk.client:Started iFlow process at ws://localhost:8090/acp
INFO:iflow_sdk._internal.transport:Connecting to ws://localhost:8090/acp
INFO:iflow_sdk.client:Stopping iFlow process...
INFO:iflow_sdk._internal.process_manager:Stopping iFlow process (PID: 49760)
WARNING:iflow_sdk._internal.process_manager:iFlow process did not terminate gracefully, forcing kill
INFO:iflow_sdk.client:Disconnected from iFlow
Traceback (most recent call last):
  File "E:\python_code\test_demo\.venv\Lib\site-packages\websockets\http11.py", line 343, in parse_headers
    line = yield from parse_line(read_line)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\python_code\test_demo\.venv\Lib\site-packages\websockets\http11.py", line 309, in parse_line
    line = yield from read_line(MAX_LINE_LENGTH)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\python_code\test_demo\.venv\Lib\site-packages\websockets\streams.py", line 46, in read_line
    raise EOFError(f"stream ends after {p} bytes, before end of line")
EOFError: stream ends after 1 bytes, before end of line

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "E:\python_code\test_demo\.venv\Lib\site-packages\websockets\client.py", line 301, in parse
    response = yield from Response.parse(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\python_code\test_demo\.venv\Lib\site-packages\websockets\http11.py", line 267, in parse
    headers = yield from parse_headers(read_line)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\python_code\test_demo\.venv\Lib\site-packages\websockets\http11.py", line 345, in parse_headers
    raise EOFError("connection closed while reading HTTP headers") from exc
EOFError: connection closed while reading HTTP headers

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "E:\python_code\test_demo\.venv\Lib\site-packages\iflow_sdk\_internal\transport.py", line 66, in connect        
    self.websocket = await asyncio.wait_for(
                     ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\10400\AppData\Roaming\uv\python\cpython-3.12.11-windows-x86_64-none\Lib\asyncio\tasks.py", line 520, in 
wait_for
    return await fut
           ^^^^^^^^^
  File "E:\python_code\test_demo\.venv\Lib\site-packages\websockets\asyncio\client.py", line 543, in __await_impl__    
    await self.connection.handshake(
  File "E:\python_code\test_demo\.venv\Lib\site-packages\websockets\asyncio\client.py", line 114, in handshake
    raise self.protocol.handshake_exc
websockets.exceptions.InvalidMessage: did not receive a valid HTTP response

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "E:\python_code\test_demo\.venv\Lib\site-packages\iflow_sdk\client.py", line 194, in connect
    await self._transport.connect()
  File "E:\python_code\test_demo\.venv\Lib\site-packages\iflow_sdk\_internal\transport.py", line 80, in connect        
    raise ConnectionError(f"WebSocket connection failed: {e}") from e
iflow_sdk._errors.ConnectionError: WebSocket connection failed: did not receive a valid HTTP response

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "E:\python_code\test_demo\test\test_flow.py", line 5, in <module>
    response = query_sync("你好", options=options)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\python_code\test_demo\.venv\Lib\site-packages\iflow_sdk\query.py", line 136, in query_sync
    return asyncio.run(query(prompt, files, options))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\10400\AppData\Roaming\uv\python\cpython-3.12.11-windows-x86_64-none\Lib\asyncio\runners.py", line 195, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "C:\Users\10400\AppData\Roaming\uv\python\cpython-3.12.11-windows-x86_64-none\Lib\asyncio\runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\10400\AppData\Roaming\uv\python\cpython-3.12.11-windows-x86_64-none\Lib\asyncio\base_events.py", line 691, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "E:\python_code\test_demo\.venv\Lib\site-packages\iflow_sdk\query.py", line 58, in query
    async with IFlowClient(options) as client:
               ^^^^^^^^^^^^^^^^^^^^
  File "E:\python_code\test_demo\.venv\Lib\site-packages\iflow_sdk\client.py", line 817, in __aenter__
    await self.connect()
  File "E:\python_code\test_demo\.venv\Lib\site-packages\iflow_sdk\client.py", line 295, in connect
    raise ConnectionError(f"Failed to connect: {e}") from e
iflow_sdk._errors.ConnectionError: Failed to connect: WebSocket connection failed: did not receive a valid HTTP response 
Exception ignored in: <function BaseSubprocessTransport.__del__ at 0x000001BB4CF4EF20>
Traceback (most recent call last):
  File "C:\Users\10400\AppData\Roaming\uv\python\cpython-3.12.11-windows-x86_64-none\Lib\asyncio\base_subprocess.py", line 126, in __del__
    self.close()
  File "C:\Users\10400\AppData\Roaming\uv\python\cpython-3.12.11-windows-x86_64-none\Lib\asyncio\base_subprocess.py", line 104, in close
    proto.pipe.close()
  File "C:\Users\10400\AppData\Roaming\uv\python\cpython-3.12.11-windows-x86_64-none\Lib\asyncio\proactor_events.py", line 109, in close
    self._loop.call_soon(self._call_connection_lost, None)
  File "C:\Users\10400\AppData\Roaming\uv\python\cpython-3.12.11-windows-x86_64-none\Lib\asyncio\base_events.py", line 799, in call_soon
    self._check_closed()
  File "C:\Users\10400\AppData\Roaming\uv\python\cpython-3.12.11-windows-x86_64-none\Lib\asyncio\base_events.py", line 545, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x000001BB4CF78860>
Traceback (most recent call last):
  File "C:\Users\10400\AppData\Roaming\uv\python\cpython-3.12.11-windows-x86_64-none\Lib\asyncio\proactor_events.py", line 116, in __del__
    _warn(f"unclosed transport {self!r}", ResourceWarning, source=self)
                               ^^^^^^^^
  File "C:\Users\10400\AppData\Roaming\uv\python\cpython-3.12.11-windows-x86_64-none\Lib\asyncio\proactor_events.py", line 80, in __repr__
    info.append(f'fd={self._sock.fileno()}')
                      ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\10400\AppData\Roaming\uv\python\cpython-3.12.11-windows-x86_64-none\Lib\asyncio\windows_utils.py", line 
102, in fileno
    raise ValueError("I/O operation on closed pipe")
ValueError: I/O operation on closed pipe
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x000001BB4CF78860>
Traceback (most recent call last):
  File "C:\Users\10400\AppData\Roaming\uv\python\cpython-3.12.11-windows-x86_64-none\Lib\asyncio\proactor_events.py", line 116, in __del__
    _warn(f"unclosed transport {self!r}", ResourceWarning, source=self)
                               ^^^^^^^^
  File "C:\Users\10400\AppData\Roaming\uv\python\cpython-3.12.11-windows-x86_64-none\Lib\asyncio\proactor_events.py", line 80, in __repr__
    info.append(f'fd={self._sock.fileno()}')
                      ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\10400\AppData\Roaming\uv\python\cpython-3.12.11-windows-x86_64-none\Lib\asyncio\windows_utils.py", line 
102, in fileno
    raise ValueError("I/O operation on closed pipe")
ValueError: I/O operation on closed pipe

您可以尝试检查一下端口问题,我按照文档运行了是可以正常连接的https://platform.iflow.cn/cli/sdk/sdk-python#连接问题