APIConnectionError: Connection error
dtSundy opened this issue · comments
Could you please help me see where the problem lies:
Thanks
The error message is as follows
Traceback (most recent call last):
File "D:\Users\e000211\AppData\Local\pypoetry\Cache\virtualenvs\backend-p8Fnr68f-py3.12\Lib\site-packages\httpx_transports\default.py", line 66, in map_httpcore_exceptions
yield
File "D:\Users\e000211\AppData\Local\pypoetry\Cache\virtualenvs\backend-p8Fnr68f-py3.12\Lib\site-packages\httpx_transports\default.py", line 366, in handle_async_request
resp = await self._pool.handle_async_request(req)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Users\e000211\AppData\Local\pypoetry\Cache\virtualenvs\backend-p8Fnr68f-py3.12\Lib\site-packages\httpcore_async\connection_pool.py", line 216, in handle_async_request
raise exc from None
File "D:\Users\e000211\AppData\Local\pypoetry\Cache\virtualenvs\backend-p8Fnr68f-py3.12\Lib\site-packages\httpcore_async\connection_pool.py", line 196, in handle_async_request
response = await connection.handle_async_request(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Users\e000211\AppData\Local\pypoetry\Cache\virtualenvs\backend-p8Fnr68f-py3.12\Lib\site-packages\httpcore_async\connection.py", line 99, in handle_async_request
raise exc
File "D:\Users\e000211\AppData\Local\pypoetry\Cache\virtualenvs\backend-p8Fnr68f-py3.12\Lib\site-packages\httpcore_async\connection.py", line 76, in handle_async_request
stream = await self._connect(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Users\e000211\AppData\Local\pypoetry\Cache\virtualenvs\backend-p8Fnr68f-py3.12\Lib\site-packages\httpcore_async\connection.py", line 122, in _connect
stream = await self._network_backend.connect_tcp(**kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Users\e000211\AppData\Local\pypoetry\Cache\virtualenvs\backend-p8Fnr68f-py3.12\Lib\site-packages\httpcore_backends\auto.py", line 30, in connect_tcp
return await self._backend.connect_tcp(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Users\e000211\AppData\Local\pypoetry\Cache\virtualenvs\backend-p8Fnr68f-py3.12\Lib\site-packages\httpcore_backends\anyio.py", line 112, in connect_tcp
with map_exceptions(exc_map):
File "D:\Users\e000211\AppData\Local\Programs\Python\Python312\Lib\contextlib.py", line 158, in exit
self.gen.throw(value)
File "D:\Users\e000211\AppData\Local\pypoetry\Cache\virtualenvs\backend-p8Fnr68f-py3.12\Lib\site-packages\httpcore_exceptions.py", line 14, in map_exceptions
raise to_exc(exc) from exc
httpcore.ConnectError: All connection attempts failed
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "D:\Users\e000211\AppData\Local\pypoetry\Cache\virtualenvs\backend-p8Fnr68f-py3.12\Lib\site-packages\openai_base_client.py", line 1470, in _request
response = await self._client.send(
^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Users\e000211\AppData\Local\pypoetry\Cache\virtualenvs\backend-p8Fnr68f-py3.12\Lib\site-packages\httpx_client.py", line 1617, in send
response = await self._send_handling_auth(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Users\e000211\AppData\Local\pypoetry\Cache\virtualenvs\backend-p8Fnr68f-py3.12\Lib\site-packages\httpx_client.py", line 1645, in _send_handling_auth
response = await self._send_handling_redirects(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Users\e000211\AppData\Local\pypoetry\Cache\virtualenvs\backend-p8Fnr68f-py3.12\Lib\site-packages\httpx_client.py", line 1682, in _send_handling_redirects
response = await self._send_single_request(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Users\e000211\AppData\Local\pypoetry\Cache\virtualenvs\backend-p8Fnr68f-py3.12\Lib\site-packages\httpx_client.py", line 1719, in _send_single_request
response = await transport.handle_async_request(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Users\e000211\AppData\Local\pypoetry\Cache\virtualenvs\backend-p8Fnr68f-py3.12\Lib\site-packages\httpx_transports\default.py", line 365, in handle_async_request
with map_httpcore_exceptions():
File "D:\Users\e000211\AppData\Local\Programs\Python\Python312\Lib\contextlib.py", line 158, in exit
self.gen.throw(value)
File "D:\Users\e000211\AppData\Local\pypoetry\Cache\virtualenvs\backend-p8Fnr68f-py3.12\Lib\site-packages\httpx_transports\default.py", line 83, in map_httpcore_exceptions
raise mapped_exc(message) from exc
httpx.ConnectError: All connection attempts failed
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "D:\Users\e000211\AppData\Local\pypoetry\Cache\virtualenvs\backend-p8Fnr68f-py3.12\Lib\site-packages\uvicorn\protocols\websockets\websockets_impl.py", line 250, in run_asgi
result = await self.app(self.scope, self.asgi_receive, self.asgi_send)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Users\e000211\AppData\Local\pypoetry\Cache\virtualenvs\backend-p8Fnr68f-py3.12\Lib\site-packages\uvicorn\middleware\proxy_headers.py", line 84, in call
return await self.app(scope, receive, send)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Users\e000211\AppData\Local\pypoetry\Cache\virtualenvs\backend-p8Fnr68f-py3.12\Lib\site-packages\fastapi\applications.py", line 276, in call
await super().call(scope, receive, send)
File "D:\Users\e000211\AppData\Local\pypoetry\Cache\virtualenvs\backend-p8Fnr68f-py3.12\Lib\site-packages\starlette\applications.py", line 122, in call
await self.middleware_stack(scope, receive, send)
File "D:\Users\e000211\AppData\Local\pypoetry\Cache\virtualenvs\backend-p8Fnr68f-py3.12\Lib\site-packages\starlette\middleware\errors.py", line 149, in call
await self.app(scope, receive, send)
File "D:\Users\e000211\AppData\Local\pypoetry\Cache\virtualenvs\backend-p8Fnr68f-py3.12\Lib\site-packages\starlette\middleware\cors.py", line 75, in call
await self.app(scope, receive, send)
File "D:\Users\e000211\AppData\Local\pypoetry\Cache\virtualenvs\backend-p8Fnr68f-py3.12\Lib\site-packages\starlette\middleware\exceptions.py", line 79, in call
raise exc
File "D:\Users\e000211\AppData\Local\pypoetry\Cache\virtualenvs\backend-p8Fnr68f-py3.12\Lib\site-packages\starlette\middleware\exceptions.py", line 68, in call
await self.app(scope, receive, sender)
File "D:\Users\e000211\AppData\Local\pypoetry\Cache\virtualenvs\backend-p8Fnr68f-py3.12\Lib\site-packages\fastapi\middleware\asyncexitstack.py", line 21, in call
raise e
File "D:\Users\e000211\AppData\Local\pypoetry\Cache\virtualenvs\backend-p8Fnr68f-py3.12\Lib\site-packages\fastapi\middleware\asyncexitstack.py", line 18, in call
await self.app(scope, receive, send)
File "D:\Users\e000211\AppData\Local\pypoetry\Cache\virtualenvs\backend-p8Fnr68f-py3.12\Lib\site-packages\starlette\routing.py", line 718, in call
await route.handle(scope, receive, send)
File "D:\Users\e000211\AppData\Local\pypoetry\Cache\virtualenvs\backend-p8Fnr68f-py3.12\Lib\site-packages\starlette\routing.py", line 341, in handle
await self.app(scope, receive, send)
File "D:\Users\e000211\AppData\Local\pypoetry\Cache\virtualenvs\backend-p8Fnr68f-py3.12\Lib\site-packages\starlette\routing.py", line 82, in app
await func(session)
File "D:\Users\e000211\AppData\Local\pypoetry\Cache\virtualenvs\backend-p8Fnr68f-py3.12\Lib\site-packages\fastapi\routing.py", line 289, in app
await dependant.call(**values)
File "D:\code\screenshot-to-code\backend\routes\generate_code.py", line 251, in stream_code
completion = await stream_openai_response(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\code\screenshot-to-code\backend\llm.py", line 58, in stream_openai_response
stream = await client.chat.completions.create(**params) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Users\e000211\AppData\Local\pypoetry\Cache\virtualenvs\backend-p8Fnr68f-py3.12\Lib\site-packages\openai\resources\chat\completions.py", line 1334, in create
return await self._post(
^^^^^^^^^^^^^^^^^
File "D:\Users\e000211\AppData\Local\pypoetry\Cache\virtualenvs\backend-p8Fnr68f-py3.12\Lib\site-packages\openai_base_client.py", line 1738, in post
return await self.request(cast_to, opts, stream=stream, stream_cls=stream_cls)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Users\e000211\AppData\Local\pypoetry\Cache\virtualenvs\backend-p8Fnr68f-py3.12\Lib\site-packages\openai_base_client.py", line 1441, in request
return await self._request(
^^^^^^^^^^^^^^^^^^^^
File "D:\Users\e000211\AppData\Local\pypoetry\Cache\virtualenvs\backend-p8Fnr68f-py3.12\Lib\site-packages\openai_base_client.py", line 1494, in _request
return await self._retry_request(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Users\e000211\AppData\Local\pypoetry\Cache\virtualenvs\backend-p8Fnr68f-py3.12\Lib\site-packages\openai_base_client.py", line 1563, in _retry_request
return await self._request(
^^^^^^^^^^^^^^^^^^^^
File "D:\Users\e000211\AppData\Local\pypoetry\Cache\virtualenvs\backend-p8Fnr68f-py3.12\Lib\site-packages\openai_base_client.py", line 1494, in _request
return await self._retry_request(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Users\e000211\AppData\Local\pypoetry\Cache\virtualenvs\backend-p8Fnr68f-py3.12\Lib\site-packages\openai_base_client.py", line 1563, in _retry_request
return await self._request(
^^^^^^^^^^^^^^^^^^^^
File "D:\Users\e000211\AppData\Local\pypoetry\Cache\virtualenvs\backend-p8Fnr68f-py3.12\Lib\site-packages\openai_base_client.py", line 1504, in _request
raise APIConnectionError(request=request) from err
openai.APIConnectionError: Connection error.
INFO: connection closed
Thanks for the full logs. The issue is likely that you aren't able to connect to OpenAI. Are you in a country that blocks OpenAI? Can you try using a proxy or VPN?
Thanks for the full logs. The issue is likely that you aren't able to connect to OpenAI. Are you in a country that blocks OpenAI? Can you try using a proxy or VPN?
The key used is provided by the company and can be called elsewhere
Maybe it's because of my local firewall, I'll try again
Yes, it’s possible a firewall issue. In the settings UI, you can also set a proxy URL.
Is the key your company has for OpenAI or a different proxy service?