Remote end closed connection without response

I’m using gpt_academic via a local socks5h proxy, but which will trigger the following error when I try to input some text in gpt_academic’s gradio based frontend:

werner@X10DAi:~$ gpt_academic 
[ENV_VAR] 尝试加载proxies,默认值:None --> 修正值:{ "http": "socks5h://localhost:18890", "https": "socks5h://localhost:18890" }
 [ENV_VAR] 成功读取环境变量proxies 
[ENV_VAR] 尝试加载USE_PROXY,默认值:False --> 修正值:True
 [ENV_VAR] 成功读取环境变量USE_PROXY 
 [PROXY] 网络代理状态:已配置。配置信息如下: {'http': 'socks5h://localhost:18890', 'https': 'socks5h://localhost:18890'} 
[ENV_VAR] 尝试加载API_URL_REDIRECT,默认值:{} --> 修正值:{"https://api.openai.com/v1/chat/completions": "https://api.chatgpt-3.vip/v1/chat/completions"}
 [ENV_VAR] 成功读取环境变量API_URL_REDIRECT 
[ENV_VAR] 尝试加载LLM_MODEL,默认值:gpt-3.5-turbo --> 修正值:gpt-4
 [ENV_VAR] 成功读取环境变量LLM_MODEL 
所有问询记录将自动保存在本地目录./gpt_log/chat_secrets.log, 请注意自我隐私保护哦!
代理配置 socks5h://localhost:18890, 代理所在地:United States - Cloudflare, Inc.
[ENV_VAR] 尝试加载API_KEY,默认值:此处填API密钥 --> 修正值:sk-xxx
 [ENV_VAR] 成功读取环境变量API_KEY 
 [API_KEY] 本项目现已支持OpenAI和Azure的api-key。也支持同时填写多个api-key,如API_KEY="openai-key1,openai-key2,azure-key3" 
 [API_KEY] 您既可以在config.py中修改api-key(s),也可以在问题输入区输入临时的api-key(s),然后回车键提交后即可生效。 
 [API_KEY] 您的 API_KEY 是: sk-nto0MuxwhqgC*** API_KEY 导入成功 
如果浏览器没有自动打开,请复制并转到以下URL:
	(亮色主题): http://localhost:33263
	(暗色主题): http://localhost:33263/?__theme=dark
正在执行一些模块的预热...
正在加载tokenizer,如果是第一次运行,可能需要一点时间下载参数
加载tokenizer完毕
正在加载tokenizer,如果是第一次运行,可能需要一点时间下载参数
加载tokenizer完毕
Traceback (most recent call last):
  File "/home/werner/.pyenv/versions/gpt_academic/lib/python3.11/site-packages/urllib3/connectionpool.py", line 790, in urlopen
    response = self._make_request(
               ^^^^^^^^^^^^^^^^^^^
  File "/home/werner/.pyenv/versions/gpt_academic/lib/python3.11/site-packages/urllib3/connectionpool.py", line 536, in _make_request
    response = conn.getresponse()
               ^^^^^^^^^^^^^^^^^^
  File "/home/werner/.pyenv/versions/gpt_academic/lib/python3.11/site-packages/urllib3/connection.py", line 461, in getresponse
    httplib_response = super().getresponse()
                       ^^^^^^^^^^^^^^^^^^^^^
  File "/home/werner/.pyenv/versions/3.11.1/lib/python3.11/http/client.py", line 1374, in getresponse
    response.begin()
  File "/home/werner/.pyenv/versions/3.11.1/lib/python3.11/http/client.py", line 318, in begin
    version, status, reason = self._read_status()
                              ^^^^^^^^^^^^^^^^^^^
  File "/home/werner/.pyenv/versions/3.11.1/lib/python3.11/http/client.py", line 287, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/werner/.pyenv/versions/gpt_academic/lib/python3.11/site-packages/requests/adapters.py", line 486, in send
    resp = conn.urlopen(
           ^^^^^^^^^^^^^
  File "/home/werner/.pyenv/versions/gpt_academic/lib/python3.11/site-packages/urllib3/connectionpool.py", line 844, in urlopen
    retries = retries.increment(
              ^^^^^^^^^^^^^^^^^^
  File "/home/werner/.pyenv/versions/gpt_academic/lib/python3.11/site-packages/urllib3/util/retry.py", line 470, in increment
    raise reraise(type(error), error, _stacktrace)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/werner/.pyenv/versions/gpt_academic/lib/python3.11/site-packages/urllib3/util/util.py", line 38, in reraise
    raise value.with_traceback(tb)
  File "/home/werner/.pyenv/versions/gpt_academic/lib/python3.11/site-packages/urllib3/connectionpool.py", line 790, in urlopen
    response = self._make_request(
               ^^^^^^^^^^^^^^^^^^^
  File "/home/werner/.pyenv/versions/gpt_academic/lib/python3.11/site-packages/urllib3/connectionpool.py", line 536, in _make_request
    response = conn.getresponse()
               ^^^^^^^^^^^^^^^^^^
  File "/home/werner/.pyenv/versions/gpt_academic/lib/python3.11/site-packages/urllib3/connection.py", line 461, in getresponse
    httplib_response = super().getresponse()
                       ^^^^^^^^^^^^^^^^^^^^^
  File "/home/werner/.pyenv/versions/3.11.1/lib/python3.11/http/client.py", line 1374, in getresponse
    response.begin()
  File "/home/werner/.pyenv/versions/3.11.1/lib/python3.11/http/client.py", line 318, in begin
    version, status, reason = self._read_status()
                              ^^^^^^^^^^^^^^^^^^^
  File "/home/werner/.pyenv/versions/3.11.1/lib/python3.11/http/client.py", line 287, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/werner/Public/repo/github.com/binary-husky/gpt_academic.git/main.py", line 305, in <module>
    main()
  File "/home/werner/Public/repo/github.com/binary-husky/gpt_academic.git/main.py", line 287, in main
    demo.queue(concurrency_count=CONCURRENT_COUNT).launch(
  File "/home/werner/.pyenv/versions/gpt_academic/lib/python3.11/site-packages/gradio/blocks.py", line 1775, in launch
    requests.get(f"{self.local_url}startup-events", verify=ssl_verify)
  File "/home/werner/.pyenv/versions/gpt_academic/lib/python3.11/site-packages/requests/api.py", line 73, in get
    return request("get", url, params=params, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/werner/.pyenv/versions/gpt_academic/lib/python3.11/site-packages/requests/api.py", line 59, in request
    return session.request(method=method, url=url, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/werner/.pyenv/versions/gpt_academic/lib/python3.11/site-packages/requests/sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/werner/.pyenv/versions/gpt_academic/lib/python3.11/site-packages/requests/sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/werner/.pyenv/versions/gpt_academic/lib/python3.11/site-packages/requests/adapters.py", line 501, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

Any hints for this problem will be helpful.

Regards,
Zhao

Most likely is that there is a firewall that is blocking your access.

If you can run the command with English messages it may help us give better suggestions.

LC_ALL=en_US.UTF-8 gpt_academic

I assume you already double-checked that your API_KEY is a valid ChatGPT key?

Apparently this package gives instructions (in config.py) about how to connect to a proxy server if needed. So, perhaps you could check whether you actually need one (just try it out with USE_PROXY=False), and if so, if you gave it the right URLs and whatever other config variables need to be set.

I really hate the kind of stack traces that you showed because they don’t give some vital pieces of information that they could easily give, such as: What was the url for the failing request?
You could improve the gradio code a bit by adding more debug info, in particular everywhere where “self.local_url” is used (or passed to requests), log what the url actually is and assert when it’s None or empty (the gradio code seems inherently unsafe in this regard). Knowing the url could make it easier to determine what exactly the problem is.

The shown Chinese messages are from the tool itself, see below for more info:

werner@X10DAi:~$ LC_ALL=en_US.UTF-8 gpt_academic
[ENV_VAR] 尝试加载proxies,默认值:None --> 修正值:{ "http": "socks5h://localhost:18890", "https": "socks5h://localhost:18890" }
 [ENV_VAR] 成功读取环境变量proxies 
[ENV_VAR] 尝试加载USE_PROXY,默认值:False --> 修正值:True
 [ENV_VAR] 成功读取环境变量USE_PROXY 
 [PROXY] 网络代理状态:已配置。配置信息如下: {'http': 'socks5h://localhost:18890', 'https': 'socks5h://localhost:18890'} 
[ENV_VAR] 尝试加载API_URL_REDIRECT,默认值:{} --> 修正值:{"https://api.openai.com/v1/chat/completions": "https://api.chatgpt-3.vip/v1/chat/completions"}
 [ENV_VAR] 成功读取环境变量API_URL_REDIRECT 
[ENV_VAR] 尝试加载LLM_MODEL,默认值:gpt-3.5-turbo --> 修正值:gpt-4
 [ENV_VAR] 成功读取环境变量LLM_MODEL 
所有问询记录将自动保存在本地目录./gpt_log/chat_secrets.log, 请注意自我隐私保护哦!
代理配置 socks5h://localhost:18890, 代理所在地:United States
[ENV_VAR] 尝试加载API_KEY,默认值:此处填API密钥 --> 修正值:sk-xxx
 [ENV_VAR] 成功读取环境变量API_KEY 
 [API_KEY] 本项目现已支持OpenAI和Azure的api-key。也支持同时填写多个api-key,如API_KEY="openai-key1,openai-key2,azure-key3" 
 [API_KEY] 您既可以在config.py中修改api-key(s),也可以在问题输入区输入临时的api-key(s),然后回车键提交后即可生效。 
 [API_KEY] 您的 API_KEY 是: sk-nto0MuxwhqgC*** API_KEY 导入成功 
如果浏览器没有自动打开,请复制并转到以下URL:
	(亮色主题): http://localhost:52115
	(暗色主题): http://localhost:52115/?__theme=dark
正在执行一些模块的预热...
正在加载tokenizer,如果是第一次运行,可能需要一点时间下载参数
加载tokenizer完毕
正在加载tokenizer,如果是第一次运行,可能需要一点时间下载参数
加载tokenizer完毕
Traceback (most recent call last):
  File "/home/werner/.pyenv/versions/gpt_academic/lib/python3.11/site-packages/urllib3/connectionpool.py", line 790, in urlopen
    response = self._make_request(
               ^^^^^^^^^^^^^^^^^^^
  File "/home/werner/.pyenv/versions/gpt_academic/lib/python3.11/site-packages/urllib3/connectionpool.py", line 536, in _make_request
    response = conn.getresponse()
               ^^^^^^^^^^^^^^^^^^
  File "/home/werner/.pyenv/versions/gpt_academic/lib/python3.11/site-packages/urllib3/connection.py", line 461, in getresponse
    httplib_response = super().getresponse()
                       ^^^^^^^^^^^^^^^^^^^^^
  File "/home/werner/.pyenv/versions/3.11.1/lib/python3.11/http/client.py", line 1374, in getresponse
    response.begin()
  File "/home/werner/.pyenv/versions/3.11.1/lib/python3.11/http/client.py", line 318, in begin
    version, status, reason = self._read_status()
                              ^^^^^^^^^^^^^^^^^^^
  File "/home/werner/.pyenv/versions/3.11.1/lib/python3.11/http/client.py", line 287, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/werner/.pyenv/versions/gpt_academic/lib/python3.11/site-packages/requests/adapters.py", line 486, in send
    resp = conn.urlopen(
           ^^^^^^^^^^^^^
  File "/home/werner/.pyenv/versions/gpt_academic/lib/python3.11/site-packages/urllib3/connectionpool.py", line 844, in urlopen
    retries = retries.increment(
              ^^^^^^^^^^^^^^^^^^
  File "/home/werner/.pyenv/versions/gpt_academic/lib/python3.11/site-packages/urllib3/util/retry.py", line 470, in increment
    raise reraise(type(error), error, _stacktrace)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/werner/.pyenv/versions/gpt_academic/lib/python3.11/site-packages/urllib3/util/util.py", line 38, in reraise
    raise value.with_traceback(tb)
  File "/home/werner/.pyenv/versions/gpt_academic/lib/python3.11/site-packages/urllib3/connectionpool.py", line 790, in urlopen
    response = self._make_request(
               ^^^^^^^^^^^^^^^^^^^
  File "/home/werner/.pyenv/versions/gpt_academic/lib/python3.11/site-packages/urllib3/connectionpool.py", line 536, in _make_request
    response = conn.getresponse()
               ^^^^^^^^^^^^^^^^^^
  File "/home/werner/.pyenv/versions/gpt_academic/lib/python3.11/site-packages/urllib3/connection.py", line 461, in getresponse
    httplib_response = super().getresponse()
                       ^^^^^^^^^^^^^^^^^^^^^
  File "/home/werner/.pyenv/versions/3.11.1/lib/python3.11/http/client.py", line 1374, in getresponse
    response.begin()
  File "/home/werner/.pyenv/versions/3.11.1/lib/python3.11/http/client.py", line 318, in begin
    version, status, reason = self._read_status()
                              ^^^^^^^^^^^^^^^^^^^
  File "/home/werner/.pyenv/versions/3.11.1/lib/python3.11/http/client.py", line 287, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/werner/Public/repo/github.com/binary-husky/gpt_academic.git/main.py", line 305, in <module>
    main()
  File "/home/werner/Public/repo/github.com/binary-husky/gpt_academic.git/main.py", line 287, in main
    demo.queue(concurrency_count=CONCURRENT_COUNT).launch(
  File "/home/werner/.pyenv/versions/gpt_academic/lib/python3.11/site-packages/gradio/blocks.py", line 1775, in launch
    requests.get(f"{self.local_url}startup-events", verify=ssl_verify)
  File "/home/werner/.pyenv/versions/gpt_academic/lib/python3.11/site-packages/requests/api.py", line 73, in get
    return request("get", url, params=params, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/werner/.pyenv/versions/gpt_academic/lib/python3.11/site-packages/requests/api.py", line 59, in request
    return session.request(method=method, url=url, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/werner/.pyenv/versions/gpt_academic/lib/python3.11/site-packages/requests/sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/werner/.pyenv/versions/gpt_academic/lib/python3.11/site-packages/requests/sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/werner/.pyenv/versions/gpt_academic/lib/python3.11/site-packages/requests/adapters.py", line 501, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

On the other hand, the above error occurs only when I run the tool for the first time after booting the computer and logging into my account. If I close the browser window after the above error occurs and restart the tool, it will work smoothly as follows:

This makes me very confused.

Yes, it’s valid.

USE_PROXY=False doesn’t trigger the error and works smoothly.

Thank you for your advice.

Regards,
Zhao

1 Like