Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

httpcore.ProxyError: 407 Proxy Authentication Required #940

Closed
Chihuahua12345 opened this issue May 8, 2024 · 6 comments
Closed

httpcore.ProxyError: 407 Proxy Authentication Required #940

Chihuahua12345 opened this issue May 8, 2024 · 6 comments
Labels
answered 🤖 The question has been answered. Will be closed automatically if no new comments question Further information is requested

Comments

@Chihuahua12345
Copy link

When I executed the sample code listed in the Quickstart, I encountered an error that said “httpcore.ProxyError: 407 Proxy Authentication Required.” I have entered the actual API key in “your-openai-key.”

Code Examples

from datasets import Dataset 
import os
from ragas import evaluate
from ragas.metrics import faithfulness, answer_correctness

os.environ["OPENAI_API_KEY"] = "your-openai-key"

data_samples = {
    'question': ['When was the first super bowl?', 'Who won the most super bowls?'],
    'answer': ['The first superbowl was held on Jan 15, 1967', 'The most super bowls have been won by The New England Patriots'],
    'contexts' : [['The First AFL–NFL World Championship Game was an American football game played on January 15, 1967, at the Los Angeles Memorial Coliseum in Los Angeles,'], 
    ['The Green Bay Packers...Green Bay, Wisconsin.','The Packers compete...Football Conference']],
    'ground_truth': ['The first superbowl was held on January 15, 1967', 'The New England Patriots have won the Super Bowl a record six times']
}

dataset = Dataset.from_dict(data_samples)

score = evaluate(dataset,metrics=[faithfulness,answer_correctness])
score.to_pandas()

Error trace

Evaluating:   0%|                                                                                | 0/4 [00:02<?, ?it/s]
Exception in thread Thread-7:
Traceback (most recent call last):
  File "[C:\Users\********\AppData\Local\Programs\Python\Python312\Lib\site-packages\httpx\_transports\default.py", line 69](file:///C:/Users/********/AppData/Local/Programs/Python/Python312/Lib/site-packages/httpx/_transports/default.py#line=68), in map_httpcore_exceptions
    yield
...
  File "[C:\Users\********\AppData\Local\Programs\Python\Python312\Lib\site-packages\httpcore\_sync\http_proxy.py", line 298](file:///C:/Users/********/AppData/Local/Programs/Python/Python312/Lib/site-packages/httpcore/_sync/http_proxy.py#line=297), in handle_request
    raise ProxyError(msg)
httpcore.ProxyError: 407 Proxy Authentication Required

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

Infos
The proxy server settings have been completed as follows, and since the installation of Python libraries is possible, it is presumed that additional authentication information is required for API calls.
$env:HTTP_PROXY=“http://...:8080”
$env:HTTPS_PROXY=“http://...:8080”

Could you please advise on how to proceed?

@Chihuahua12345 Chihuahua12345 added the question Further information is requested label May 8, 2024
@jjmachan
Copy link
Member

jjmachan commented Jun 1, 2024

are you still facing the issue @Chihuahua12345 ?

this seems like something to do with the networks, we can debug it more if your still facing it

@Chihuahua12345
Copy link
Author

Thank you for your response. The situation has not improved and I would like to correct the program if possible.

@jjmachan
Copy link
Member

jjmachan commented Jun 4, 2024

more than happy to help 🙂

can you provide me with some more information?

  1. can you run langchain openai quickstart and check if there are any errors
  2. are you using and VPN services or any other proxy for work?

if you provide both (esp 1.) we will get a better idea

@Chihuahua12345
Copy link
Author

Thank you for your response.
I executed the code as follows, but I still encountered an error related to the proxy.
Since I am using a secure gateway that includes VPN functionality, are any additional settings required?

Code

from getpass import getpass
OPENAI_API_KEY = getpass()

import os
os.environ["OPENAI_API_KEY"] = OPENAI_API_KEY

from langchain_core.prompts import PromptTemplate
from langchain_openai import OpenAI

template = """Question: {question}
Answer: Let's think step by step."""
prompt = PromptTemplate.from_template(template)

import httpx
llm = OpenAI(model_name="gpt-3.5-turbo-instruct", http_client=httpx.Client(proxies="http://**************:8080"))
llm_chain = prompt | llm

question = "What NFL team won the Super Bowl in the year Justin Beiber was born?"
llm_chain.invoke(question)

Error trace

ProxyError                                Traceback (most recent call last)
File [~\***\***\site-packages\httpx\_transports\default.py:69](http://localhost:8888/~/***/***/***/Lib/site-packages/httpx/_transports/default.py#line=68), in map_httpcore_exceptions()
     68 try:
---> 69     yield
     70 except Exception as exc:
...
ProxyError: 407 Proxy Authentication Required

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

ProxyError                                Traceback (most recent call last)
File [~\***\***\site-packages\openai\_base_client.py:950](http://localhost:8888/~/***/***/***/Lib/site-packages/openai/_base_client.py#line=949), in SyncAPIClient._request(self, cast_to, options, remaining_retries, stream, stream_cls)
    949 try:
--> 950     response = self._client.send(
    951         request,
    952         stream=stream or self._should_stream_response_body(request=request),
    953         **kwargs,
    954     )
    955 except httpx.TimeoutException as err:
...
ProxyError: 407 Proxy Authentication Required

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

APIConnectionError                        Traceback (most recent call last)
Cell In[3], line 19
     16 llm_chain = prompt | llm
     18 question = "What NFL team won the Super Bowl in the year Justin Beiber was born?"
---> 19 llm_chain.invoke(question)
...
File [~\***\***\site-packages\openai\_base_client.py:984](http://localhost:8888/~/***/***/***/Lib/site-packages/openai/_base_client.py#line=983), in SyncAPIClient._request(self, cast_to, options, remaining_retries, stream, stream_cls)
    974         return self._retry_request(
    975             options,
    976             cast_to,
   (...)
    980             response_headers=None,
    981         )
    983     log.debug("Raising connection error")
--> 984     raise APIConnectionError(request=request) from err
    986 log.debug(
    987     'HTTP Request: %s %s "%i %s"', request.method, request.url, response.status_code, response.reason_phrase
    988 )
    990 try:

APIConnectionError: Connection error.

@jjmachan
Copy link
Member

jjmachan commented Jun 6, 2024

you will have to configure langchain to use the VPN/proxy you have setup. I was not able to find a lot of resources but try langchain-ai/langchain#1423

but how does your application communicate with the LLM then while developing locally?

@jjmachan jjmachan added the answered 🤖 The question has been answered. Will be closed automatically if no new comments label Jun 6, 2024
Copy link

It seems the issue was answered, closing this now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
answered 🤖 The question has been answered. Will be closed automatically if no new comments question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants