anthropics / anthropic-quickstarts

A collection of projects designed to help developers quickly get started with building deployable applications using the Anthropic API
MIT License
6.19k stars 781 forks source link

APIConnectionError: Connection error. #85

Open TechieHank opened 3 days ago

TechieHank commented 3 days ago

I have installed the docker image and I have tested that my via curl and my API key can talk to Anthropic. When I run the docker container, noVNC starts and I can even browse the web, but when I run a prompt for the API to work, I get this error message:

File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/streamlit/runtime/scriptrunner/exec_code.py", line 88, in exec_func_with_error_handling result = func() ^^^^^^ File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 579, in code_to_exec exec(code, module.dict) File "/home/computeruse/computer_use_demo/streamlit.py", line 357, in asyncio.run(main()) File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/asyncio/runners.py", line 190, in run return runner.run(main) ^^^^^^^^^^^^^^^^ File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/asyncio/runners.py", line 118, in run return self._loop.run_until_complete(task) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete return future.result() ^^^^^^^^^^^^^^^ File "/home/computeruse/computer_use_demo/streamlit.py", line 213, in main st.session_state.messages = await sampling_loop( ^^^^^^^^^^^^^^^^^^^^

Thanks in advance for guidance on how to fix this issue.

TechieHank commented 3 days ago

Screenshot 2024-10-23 at 10 52 14 AM

rvadhavk commented 3 days ago

I had the same error message and found more info in the logs in terminal where I started the container: httpx.LocalProtocolError: Illegal header value b'<REDACTED> '

Turns out I had a trailing space when I pasted my API key.

TechieHank commented 3 days ago

@rvadhavk - Thanks for the feedback. I prune all my containers from docker and re-ran bash script without any trailing spaces. Unfortunately - the same issue is happening :( - I did tried to do a sudo apt-get update inside the docker container and it started complaining about a certificate.

Screenshot 2024-10-23 at 5 48 02 PM

x5a commented 3 days ago

@TechieHank are you on a network that has a firewall/proxy that re-encrypts traffic?

Regardless, I updated the latest image with a more verbose error log - can you post the traceback after doing a docker pull ghcr.io/anthropics/computer-use-demo:latest and restarting your container?

moo1o commented 3 days ago

Are you using an intranet? I may have the same problem as you, but I also had a Connection Error and the problem was with the certificate. So I updated the certificate and it was fixed.

TechieHank commented 2 days ago

@TechieHank are you on a network that has a firewall/proxy that re-encrypts traffic?

Regardless, I updated the latest image with a more verbose error log - can you post the traceback after doing a docker pull ghcr.io/anthropics/computer-use-demo:latest and restarting your container?

@x5a - Here's the Traceback after doing an update of the image:

File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/httpx/_transports/default.py", line 72, in map_httpcore_exceptions yield

File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/httpx/_transports/default.py", line 236, in handle_request resp = self._pool.handle_request(req) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/httpcore/_sync/connection_pool.py", line 216, in handle_request raise exc from None

File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/httpcore/_sync/connection_pool.py", line 196, in handle_request response = connection.handle_request( ^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/httpcore/_sync/connection.py", line 99, in handle_request raise exc

File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/httpcore/_sync/connection.py", line 76, in handle_request stream = self._connect(request) ^^^^^^^^^^^^^^^^^^^^^^

File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/httpcore/_sync/connection.py", line 154, in _connect stream = stream.start_tls(**kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/httpcore/_backends/sync.py", line 152, in start_tls with map_exceptions(exc_map):

File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/contextlib.py", line 155, in exit self.gen.throw(typ, value, traceback)

File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/httpcore/_exceptions.py", line 14, in map_exceptions raise to_exc(exc) from exc

httpcore.ConnectError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1006)

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

Traceback (most recent call last):

File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/anthropic/_base_client.py", line 990, in _request response = self._client.send( ^^^^^^^^^^^^^^^^^^

File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/httpx/_client.py", line 926, in send response = self._send_handling_auth( ^^^^^^^^^^^^^^^^^^^^^^^^^

File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/httpx/_client.py", line 954, in _send_handling_auth response = self._send_handling_redirects( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/httpx/_client.py", line 991, in _send_handling_redirects response = self._send_single_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/httpx/_client.py", line 1027, in _send_single_request response = transport.handle_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/httpx/_transports/default.py", line 235, in handle_request with map_httpcore_exceptions():

File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/contextlib.py", line 155, in exit self.gen.throw(typ, value, traceback)

File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/httpx/_transports/default.py", line 89, in map_httpcore_exceptions raise mapped_exc(message) from exc

httpx.ConnectError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1006)

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

Traceback (most recent call last):

File "/home/computeruse/computer_use_demo/loop.py", line 132, in sampling_loop raw_response = client.beta.messages.with_raw_response.create( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/anthropic/_legacy_response.py", line 377, in wrapped return cast(LegacyAPIResponse[R], func(*args, **kwargs)) ^^^^^^^^^^^^^^^^^^^^^

File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/anthropic/_utils/_utils.py", line 274, in wrapper return func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^

File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/anthropic/resources/beta/messages/messages.py", line 896, in create return self._post( ^^^^^^^^^^^

File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/anthropic/_base_client.py", line 1277, in post return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/anthropic/_base_client.py", line 954, in request return self._request( ^^^^^^^^^^^^^^

File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/anthropic/_base_client.py", line 1014, in _request return self._retry_request( ^^^^^^^^^^^^^^^^^^^^

File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/anthropic/_base_client.py", line 1092, in _retry_request return self._request( ^^^^^^^^^^^^^^

File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/anthropic/_base_client.py", line 1014, in _request return self._retry_request( ^^^^^^^^^^^^^^^^^^^^

File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/anthropic/_base_client.py", line 1092, in _retry_request return self._request( ^^^^^^^^^^^^^^

File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/anthropic/_base_client.py", line 1024, in _request raise APIConnectionError(request=request) from err

anthropic.APIConnectionError: Connection error.

TechieHank commented 2 days ago

Are you using an intranet? I may have the same problem as you, but I also had a Connection Error and the problem was with the certificate. So I updated the certificate and it was fixed.

Thanks for the feedback @moo1o - What command did you use to update it? I assume you did the update inside the container Debian VM?

moo1o commented 2 days ago

@TechieHank I succeeded by following the steps below.

  1. Access api.anthropic.com, check the valid certificate information, and extract it.
  2. Check the certificate location on your PC with pip show certifi.
  3. In the certificate location, paste the certificate information extracted in step 1 at the end of the cacerti.pem file.
my-other-github-account commented 1 day ago

Having a somewhat similar error while using the Docker container, but it only occurs intermittently, and I can rerun in the same container and it starts working again - so isn't a general failure. Any idea why this might only happen intermittently, and what I can do to fix it for the Docker container?

File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/httpx/_transports/default.py", line 72, in map_httpcore_exceptions
    yield

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/httpx/_transports/default.py", line 236, in handle_request
    resp = self._pool.handle_request(req)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/httpcore/_sync/connection_pool.py", line 216, in handle_request
    raise exc from None

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/httpcore/_sync/connection_pool.py", line 196, in handle_request
    response = connection.handle_request(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/httpcore/_sync/connection.py", line 101, in handle_request
    return self._connection.handle_request(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/httpcore/_sync/http11.py", line 143, in handle_request
    raise exc

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/httpcore/_sync/http11.py", line 113, in handle_request
    ) = self._receive_response_headers(**kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/httpcore/_sync/http11.py", line 186, in _receive_response_headers
    event = self._receive_event(timeout=timeout)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/httpcore/_sync/http11.py", line 224, in _receive_event
    data = self._network_stream.read(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/httpcore/_backends/sync.py", line 124, in read
    with map_exceptions(exc_map):

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/contextlib.py", line 155, in __exit__
    self.gen.throw(typ, value, traceback)

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/httpcore/_exceptions.py", line 14, in map_exceptions
    raise to_exc(exc) from exc

httpcore.ReadError: [SSL: SSLV3_ALERT_BAD_RECORD_MAC] sslv3 alert bad record mac (_ssl.c:2580)

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

Traceback (most recent call last):

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/anthropic/_base_client.py", line 990, in _request
    response = self._client.send(
               ^^^^^^^^^^^^^^^^^^

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/httpx/_client.py", line 926, in send
    response = self._send_handling_auth(
               ^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/httpx/_client.py", line 954, in _send_handling_auth
    response = self._send_handling_redirects(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/httpx/_client.py", line 991, in _send_handling_redirects
    response = self._send_single_request(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/httpx/_client.py", line 1027, in _send_single_request
    response = transport.handle_request(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/httpx/_transports/default.py", line 235, in handle_request
    with map_httpcore_exceptions():

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/contextlib.py", line 155, in __exit__
    self.gen.throw(typ, value, traceback)

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/httpx/_transports/default.py", line 89, in map_httpcore_exceptions
    raise mapped_exc(message) from exc

httpx.ReadError: [SSL: SSLV3_ALERT_BAD_RECORD_MAC] sslv3 alert bad record mac (_ssl.c:2580)

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

Traceback (most recent call last):

  File "/home/computeruse/computer_use_demo/loop.py", line 132, in sampling_loop
    raw_response = client.beta.messages.with_raw_response.create(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/anthropic/_legacy_response.py", line 377, in wrapped
    return cast(LegacyAPIResponse[R], func(*args, **kwargs))
                                      ^^^^^^^^^^^^^^^^^^^^^

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/anthropic/_utils/_utils.py", line 274, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/anthropic/resources/beta/messages/messages.py", line 896, in create
    return self._post(
           ^^^^^^^^^^^

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/anthropic/_base_client.py", line 1277, in post
    return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/anthropic/_base_client.py", line 954, in request
    return self._request(
           ^^^^^^^^^^^^^^

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/anthropic/_base_client.py", line 1014, in _request
    return self._retry_request(
           ^^^^^^^^^^^^^^^^^^^^

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/anthropic/_base_client.py", line 1092, in _retry_request
    return self._request(
           ^^^^^^^^^^^^^^

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/anthropic/_base_client.py", line 1014, in _request
    return self._retry_request(
           ^^^^^^^^^^^^^^^^^^^^

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/anthropic/_base_client.py", line 1092, in _retry_request
    return self._request(
           ^^^^^^^^^^^^^^

  File "/home/computeruse/.pyenv/versions/3.11.6/lib/python3.11/site-packages/anthropic/_base_client.py", line 1024, in _request
    raise APIConnectionError(request=request) from err

anthropic.APIConnectionError: Connection error.
JosePortoMonokera commented 1 day ago

Guys... I tried everything without sucess. having the same error. Seems to be a problem with the container.