AzureOpenAI APIConnectionError --lacks protocol http(Request URL is missing an 'http://' or 'https://' protocol.)

Xinling Wang 0 Reputation points
2024-09-10T16:47:08.83+00:00

Hi, I encountered a error for days. My project has apiconnection error while running a docker image, but works fine locally.

Error message is : APIConnectionError('Connection error.')Traceback (most recent call last):

File "/usr/local/lib/python3.11/site-packages/httpx/_transports/default.py", line 69, in map_httpcore_exceptions

yield

File "/usr/local/lib/python3.11/site-packages/httpx/_transports/default.py", line 233, in handle_request

resp = self._pool.handle_request(req)

       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/usr/local/lib/python3.11/site-packages/httpcore/_sync/connection_pool.py", line 167, in handle_request

raise UnsupportedProtocol(

httpcore.UnsupportedProtocol: Request URL is missing an 'http://' or 'https://' protocol.

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

Traceback (most recent call last):

File "/usr/local/lib/python3.11/site-packages/openai/_base_client.py", line 962, in _request

response = self._client.send(

           ^^^^^^^^^^^^^^^^^^

File "/usr/local/lib/python3.11/site-packages/httpx/_client.py", line 914, in send

response = self._send_handling_auth(

           ^^^^^^^^^^^^^^^^^^^^^^^^^

File "/usr/local/lib/python3.11/site-packages/httpx/_client.py", line 942, in _send_handling_auth

response = self._send_handling_redirects(

           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/usr/local/lib/python3.11/site-packages/httpx/_client.py", line 979, in _send_handling_redirects

response = self._send_single_request(request)

           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/usr/local/lib/python3.11/site-packages/httpx/_client.py", line 1015, in _send_single_request

response = transport.handle_request(request)

           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/usr/local/lib/python3.11/site-packages/httpx/_transports/default.py", line 232, in handle_request

with map_httpcore_exceptions():

File "/usr/local/lib/python3.11/contextlib.py", line 158, in exit

self.gen.throw(typ, value, traceback)

File "/usr/local/lib/python3.11/site-packages/httpx/_transports/default.py", line 86, in map_httpcore_exceptions

raise mapped_exc(message) from exc

httpx.UnsupportedProtocol: Request URL is missing an 'http://' or 'https://' protocol.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "/usr/local/lib/python3.11/site-packages/httpx/_transports/default.py", line 69, in map_httpcore_exceptions

yield

File "/usr/local/lib/python3.11/site-packages/httpx/_transports/default.py", line 233, in handle_request

resp = self._pool.handle_request(req)

       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/usr/local/lib/python3.11/site-packages/httpcore/_sync/connection_pool.py", line 167, in handle_request

raise UnsupportedProtocol(

httpcore.UnsupportedProtocol: Request URL is missing an 'http://' or 'https://' protocol.

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

Traceback (most recent call last):

File "/usr/local/lib/python3.11/site-packages/openai/_base_client.py", line 962, in _request

response = self._client.send(

           ^^^^^^^^^^^^^^^^^^

File "/usr/local/lib/python3.11/site-packages/httpx/_client.py", line 914, in send

response = self._send_handling_auth(

           ^^^^^^^^^^^^^^^^^^^^^^^^^

File "/usr/local/lib/python3.11/site-packages/httpx/_client.py", line 942, in _send_handling_auth

response = self._send_handling_redirects(

           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/usr/local/lib/python3.11/site-packages/httpx/_client.py", line 979, in _send_handling_redirects

response = self._send_single_request(request)

           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/usr/local/lib/python3.11/site-packages/httpx/_client.py", line 1015, in _send_single_request

response = transport.handle_request(request)

           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/usr/local/lib/python3.11/site-packages/httpx/_transports/default.py", line 232, in handle_request

with map_httpcore_exceptions():

File "/usr/local/lib/python3.11/contextlib.py", line 158, in exit

self.gen.throw(typ, value, traceback)

File "/usr/local/lib/python3.11/site-packages/httpx/_transports/default.py", line 86, in map_httpcore_exceptions

raise mapped_exc(message) from exc

httpx.UnsupportedProtocol: Request URL is missing an 'http://' or 'https://' protocol.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "/usr/local/lib/python3.11/site-packages/httpx/_transports/default.py", line 69, in map_httpcore_exceptions

yield

File "/usr/local/lib/python3.11/site-packages/httpx/_transports/default.py", line 233, in handle_request

resp = self._pool.handle_request(req)

       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/usr/local/lib/python3.11/site-packages/httpcore/_sync/connection_pool.py", line 167, in handle_request

raise UnsupportedProtocol(

httpcore.UnsupportedProtocol: Request URL is missing an 'http://' or 'https://' protocol.

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

Traceback (most recent call last):

File "/usr/local/lib/python3.11/site-packages/openai/_base_client.py", line 962, in _request

response = self._client.send(

           ^^^^^^^^^^^^^^^^^^

File "/usr/local/lib/python3.11/site-packages/httpx/_client.py", line 914, in send

response = self._send_handling_auth(

           ^^^^^^^^^^^^^^^^^^^^^^^^^

File "/usr/local/lib/python3.11/site-packages/httpx/_client.py", line 942, in _send_handling_auth

response = self._send_handling_redirects(

           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/usr/local/lib/python3.11/site-packages/httpx/_client.py", line 979, in _send_handling_redirects

response = self._send_single_request(request)

           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/usr/local/lib/python3.11/site-packages/httpx/_client.py", line 1015, in _send_single_request

response = transport.handle_request(request)

           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/usr/local/lib/python3.11/site-packages/httpx/_transports/default.py", line 232, in handle_request

with map_httpcore_exceptions():

File "/usr/local/lib/python3.11/contextlib.py", line 158, in exit

self.gen.throw(typ, value, traceback)

File "/usr/local/lib/python3.11/site-packages/httpx/_transports/default.py", line 86, in map_httpcore_exceptions

raise mapped_exc(message) from exc

httpx.UnsupportedProtocol: Request URL is missing an 'http://' or 'https://' protocol.

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

Traceback (most recent call last):

File "/usr/local/lib/python3.11/site-packages/langchain_core/runnables/base.py", line 2505, in invoke

input = step.invoke(input, config, **kwargs)

        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/usr/local/lib/python3.11/site-packages/langchain_core/runnables/base.py", line 3152, in invoke

output = {key: future.result() for key, future in zip(steps, futures)}

         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/usr/local/lib/python3.11/site-packages/langchain_core/runnables/base.py", line 3152, in <dictcomp>

output = {key: future.result() for key, future in zip(steps, futures)}

               ^^^^^^^^^^^^^^^

File "/usr/local/lib/python3.11/concurrent/futures/_base.py", line 456, in result

return self.__get_result()

       ^^^^^^^^^^^^^^^^^^^

File "/usr/local/lib/python3.11/concurrent/futures/_base.py", line 401, in __get_result

raise self._exception

File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run

result = self.fn(*self.args, **self.kwargs)

         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/usr/local/lib/python3.11/site-packages/langchain_core/runnables/base.py", line 2507, in invoke

input = step.invoke(input, config)

        ^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/usr/local/lib/python3.11/site-packages/langchain_core/language_models/chat_models.py", line 248, in invoke

self.generate_prompt(

File "/usr/local/lib/python3.11/site-packages/langchain_core/language_models/chat_models.py", line 677, in generate_prompt

return self.generate(prompt_messages, stop=stop, callbacks=callbacks, **kwargs)

       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/usr/local/lib/python3.11/site-packages/langchain_core/language_models/chat_models.py", line 534, in generate

raise e

File "/usr/local/lib/python3.11/site-packages/langchain_core/language_models/chat_models.py", line 524, in generate

self._generate_with_cache(

File "/usr/local/lib/python3.11/site-packages/langchain_core/language_models/chat_models.py", line 749, in _generate_with_cache

result = self._generate(

         ^^^^^^^^^^^^^^^

File "/usr/local/lib/python3.11/site-packages/langchain_openai/chat_models/base.py", line 549, in _generate

response = self.client.create(messages=message_dicts, **params)

           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/usr/local/lib/python3.11/site-packages/openai/_utils/_utils.py", line 277, in wrapper

return func(*args, **kwargs)

       ^^^^^^^^^^^^^^^^^^^^^

File "/usr/local/lib/python3.11/site-packages/openai/resources/chat/completions.py", line 643, in create

return self._post(

       ^^^^^^^^^^^

File "/usr/local/lib/python3.11/site-packages/openai/_base_client.py", line 1250, in post

return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))

                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/usr/local/lib/python3.11/site-packages/openai/_base_client.py", line 931, in request

return self._request(

       ^^^^^^^^^^^^^^

File "/usr/local/lib/python3.11/site-packages/openai/_base_client.py", line 986, in _request

return self._retry_request(

       ^^^^^^^^^^^^^^^^^^^^

File "/usr/local/lib/python3.11/site-packages/openai/_base_client.py", line 1063, in _retry_request

return self._request(

       ^^^^^^^^^^^^^^

File "/usr/local/lib/python3.11/site-packages/openai/_base_client.py", line 986, in _request

return self._retry_request(

       ^^^^^^^^^^^^^^^^^^^^

File "/usr/local/lib/python3.11/site-packages/openai/_base_client.py", line 1063, in _retry_request

return self._request(

       ^^^^^^^^^^^^^^

File "/usr/local/lib/python3.11/site-packages/openai/_base_client.py", line 996, in _request

raise APIConnectionError(request=request) from err

openai.APIConnectionError: Connection error.

Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
4,080 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Sina Salam 22,031 Reputation points Volunteer Moderator
    2024-09-10T20:41:19.6066667+00:00

    Hello Xinling Wang,

    Welcome to the Microsoft Q&A and thank you for posting your questions here.

    I understand that you your project has API connection error while running a docker image but works fine locally.

    Yes, it will work locally but missing a URL protocol such as http:// or https:// will not make it work on production environment. The error suggests that the request URL is missing the 'http://' or 'https://' protocol.

    So, therefore, look at configuration files used by your application such as .env files, config files, or any other place where you specify the API endpoint. Ensure that the URLs in these configuration files or in your Docker container environment variables include the full URL with the protocol. For example, instead of setting API_URL=api.example.com, set it as API_URL=http://api.example.com or API_URL=https://api.example.com

    Also, if the URL is being constructed or used within your application code, review the relevant sections to ensure the URL includes the protocol like the below:

    # Example in Python
    api_url = os.getenv('API_URL', 'http://default.api.example.com')
    

    I hope this is helpful! Do not hesitate to let me know if you have any other questions.

    Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.