binary-husky/gpt_academic · error · ConnectionRefusedError
无法下载资源{txt},请检查。
Error message
无法下载资源{txt},请检查。 What it means
Raised as ConnectionRefusedError when a plugin receives an http(s) URL and requests.get(txt, proxies=proxies) throws any exception. The bare except swallows the real cause (DNS failure, TLS error, timeout, bad proxy), so the original network error is lost. It comes from the file-download branch of the wildcard-path resolution helper in crazy_utils (txt.startswith('http')).
Source
Thrown at crazy_functions/crazy_utils.py:567
返回值
- success: 布尔值,表示函数是否成功执行。
- file_manifest: 文件路径列表,里面包含以指定类型为后缀名的所有文件的绝对路径。
- project_folder: 字符串,表示文件所在的文件夹路径。如果是网络上的文件,就是临时文件夹的路径。
该函数详细注释已添加,请确认是否满足您的需要。
"""
import glob, os
success = True
if txt.startswith('http'):
# 网络的远程文件
import requests
from toolbox import get_conf
from toolbox import get_log_folder, gen_time_str
proxies = get_conf('proxies')
try:
r = requests.get(txt, proxies=proxies)
except:
raise ConnectionRefusedError(f"无法下载资源{txt},请检查。")
path = os.path.join(get_log_folder(plugin_name='web_download'), gen_time_str()+type)
with open(path, 'wb+') as f: f.write(r.content)
project_folder = get_log_folder(plugin_name='web_download')
file_manifest = [path]
elif txt.endswith(type):
# 直接给定文件
file_manifest = [txt]
project_folder = os.path.dirname(txt)
elif os.path.exists(txt):
# 本地路径,递归搜索
project_folder = txt
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*'+type, recursive=True)]
if len(file_manifest) == 0:
success = False
else:
project_folder = None
file_manifest = []
success = FalseView on GitHub (pinned to d6bde0fa54)
Solutions
- Check connectivity to the URL from the same machine: curl -x "$proxy" <url> using the proxy from get_conf('proxies')
- Verify the proxies setting in config (set USE_PROXY=False or fix the proxy address/port)
- Reproduce the real error in a REPL: import requests; requests.get(txt, proxies=get_conf('proxies'), timeout=30) to see the underlying exception
- Patch the bare except to a targeted one and include the cause, e.g. except requests.RequestException as e: raise ConnectionRefusedError(f'无法下载资源{txt}: {e}')
- Add a timeout=... argument to requests.get so stalls fail fast instead of hanging
Example fix
// before
try:
r = requests.get(txt, proxies=proxies)
except:
raise ConnectionRefusedError(f"无法下载资源{txt},请检查。")
// after
try:
r = requests.get(txt, proxies=proxies, timeout=60)
except Exception as e:
raise ConnectionRefusedError(f"无法下载资源{txt}:{e!r}") from e Defensive patterns
Strategy: retry
Validate before calling
import requests
from toolbox import get_conf
def url_reachable(txt, timeout=10):
try:
proxies = get_conf('proxies')
requests.head(txt, proxies=proxies, timeout=timeout, allow_redirects=True)
return True
except requests.RequestException:
return False Type guard
def is_downloadable_url(txt: str) -> bool:
return txt.startswith('http') and '://' in txt Try / catch
try:
files = resolve_wildcard_path(txt, type)
except ConnectionRefusedError as e:
# probe for the real cause the bare except hid
import requests
try:
requests.head(txt, proxies=get_conf('proxies'), timeout=10)
except requests.RequestException as cause:
log.error(f'download failed, root cause: {cause!r}')
raise Prevention
- Validate URL reachability with a short HEAD request before invoking the plugin
- Keep proxies/USE_PROXY config accurate for the deployment network
- Always pass a timeout to requests calls; the current call has none and can hang
- Never rely on the message text for diagnosis — the bare except discards the cause, so log your own probe
When it happens
Trigger: Calling a plugin with txt='https://...' where the host is unreachable, DNS fails, the URL scheme is mistyped (e.g. 'http:/example.com'), or get_conf('proxies') returns a proxy that refuses connections. Note requests.get is called with no timeout, so a hung connection can also hang the plugin indefinitely before any exception.
Common situations: Misconfigured USE_PROXY/proxies in shared_utils/config (proxy pointing at a dead local port like 7890), corporate networks blocking the target, typo'd URL, or offline environments. The bare except makes the real reason invisible, which is the main pain point.
Related errors
- 没有找到可用的镜像站点
- 所有可用镜像站点均无法完成下载
- 无法下载论文 {self.doi},所有重试都失败了
- Request to the target service failed: {str(e)}
- 在线搜索失败!\n{Exceptions}
AI-assisted analysis of binary-husky/gpt_academic@d6bde0fa54 (2026-08-14).
Data as JSON: /api/errors/cf7027e59fd5731d.
Report an issue: GitHub.