排查问题

aria2 故障排除

粘贴 aria2 打印的错误,或按主题浏览。下面的大多数信息都是我们用 aria2 1.37.0 故意制造出来的,你能看到 aria2 的原始输出、它的含义以及修复方法。

最后更新: 已用 aria2 1.37.0 测试

安装

aria2c: command not found(找不到命令)

错误信息
aria2c: command not found
'aria2c' is not recognized as an internal or external command

aria2 没有安装,或者它所在的文件夹不在 PATH 中。

解决方法

安装 aria2(sudo apt install aria2、brew install aria2、winget install -e --id aria2.aria2),然后打开新的终端。在 Windows 上如果是自己解压的,请把该文件夹加入 Path,或用完整路径运行。用 aria2c --version 检查。

error while loading shared libraries(共享库缺失)

错误信息
error while loading shared libraries: libcares.so.2: cannot open shared object file: No such file or directory

自己编译或从别处复制的 aria2 程序需要系统中没有的库。

解决方法

改用发行版的包管理器安装 aria2,它会带上正确的库。如果必须使用那个程序,请安装报错中提到的库(例如 Debian/Ubuntu 上的 libc-ares2)。

Windows:找不到某个 .dll

错误信息
The code execution cannot proceed because libssh2.dll was not found.

这是需要额外 DLL 的非官方 aria2c.exe。

解决方法

使用 aria2 发布页面上的官方 Windows 压缩包,或 winget install -e --id aria2.aria2;官方版本不需要额外的 DLL。

macOS:“无法打开,因为无法验证开发者”

错误信息
"aria2c" cannot be opened because the developer cannot be verified.

macOS 会阻止未经公证的下载程序。

解决方法

用 Homebrew 安装(brew install aria2)可以避免这个警告。否则请在“系统设置 → 隐私与安全性”中允许一次。

配置与启动

Unknown option(未知选项)

错误信息 · ✓ 已用 aria2 1.37.0 复现
[WARN] Unknown option: ca-bundle=/etc/ssl/cert.pem

aria2.conf 或命令行中的某个键名拼错了或不存在。aria2 会忽略它照常启动,所以这项设置悄悄失效。

解决方法

在选项参考中查找正确的名称。常见的例子:ca-bundle 并不存在,正确的选项是 ca-certificate。

Parse error in aria2.conf(配置文件解析错误)

退出码 28
错误信息 · ✓ 已用 aria2 1.37.0 复现
Parse error in aria2.conf
errorCode=1 Bad number 16 # sixteen

aria2 无法读取配置文件中的某个值,拒绝启动(退出码 28)。

解决方法

看错误信息的下一行,它会指出是哪个选项。注释必须单独成行(split=16 # 注释 会失败),引号也不会被去掉。配置生成器可以生成正确的文件。

must be between 1 and 16(超出范围)

退出码 28
错误信息 · ✓ 已用 aria2 1.37.0 复现
errorCode=1 max-connection-per-server must be between 1 and 16.

某个值超出了允许范围,aria2 不会启动。

解决方法

max-connection-per-server 只允许 1 到 16。其他选项可以用 aria2c --help=选项名 查看允许的值。

Failed to open the file …aria2.session(会话文件不存在)

退出码 1
错误信息 · ✓ 已用 aria2 1.37.0 复现
errorCode=1 Failed to open the file /root/.aria2/aria2.session, cause: File not found or it is a directory

input-file 指向的会话文件还不存在,所以 aria2 停止了。

解决方法

先创建一次:mkdir -p ~/.aria2 && touch ~/.aria2/aria2.session(Windows:New-Item -ItemType File -Force "$env:USERPROFILE\.aria2\aria2.session")。

No files to download.(没有要下载的文件)

退出码 0
错误信息 · ✓ 已用 aria2 1.37.0 复现
No files to download.

你的配置设置了 input-file,aria2 会从会话文件读取下载任务,并忽略命令行中的链接。

解决方法

单次下载时,在这次运行中把它清空:aria2c --input-file= URL。对 RPC 服务来说这种行为是正确的。

下载保存到了名为 "~" 的文件夹

aria2 不会在 aria2.conf 中展开 ~,而是创建一个名字就叫 "~" 的文件夹。

解决方法

改写成 ${HOME},例如 dir=${HOME}/Downloads。在终端里 ~ 照常可用。

下载走了一个你没设置过的代理

和很多命令行工具一样,aria2 会读取 http_proxy、https_proxy 和 all_proxy 环境变量。

解决方法

用 env | grep -i proxy 检查。用 --no-proxy=主机列表 排除主机,或在没有这些变量的环境中启动 aria2。

HTTP 与网络

status=403(禁止访问)

退出码 22
错误信息 · ✓ 已用 aria2 1.37.0 复现
errorCode=22 The response status is not successful. status=403

服务器拒绝了请求。通常是链接需要你的登录 Cookie、Referer,或已经过期;有些服务器也会拒绝过多的连接。

解决方法

用会转发 Cookie 的扩展从浏览器发送下载(见浏览器指南),或用 --load-cookies、--header 传入。链接过期就重新获取,并试试 -x 4。

Resource not found(404)

退出码 3
错误信息 · ✓ 已用 aria2 1.37.0 复现
errorCode=3 Resource not found

该地址上什么都没有(退出码 3)。

解决方法

检查链接是否有错字、文件是否已移动。从下载页面复制的链接常常是临时的,请重新复制。

status=429(请求过多)

退出码 22
错误信息 · ✓ 已用 aria2 1.37.0 复现
errorCode=22 The response status is not successful. status=429

服务器限制了你的请求次数。aria2 以退出码 22 报告它。

解决方法

减少连接数(-x 4)和同时下载数(-j 1),并加上 --retry-wait=30。

status=503(服务不可用)

退出码 29
错误信息 · ✓ 已用 aria2 1.37.0 复现
errorCode=29 The response status is not successful. status=503

服务器过载或在维护(退出码 29)。也可能是它允许的连接数比你打开的少。

解决方法

稍后用 --max-tries=0 --retry-wait=30 重试,并降低 -x。

Authorization failed(401,认证失败)

退出码 24
错误信息 · ✓ 已用 aria2 1.37.0 复现
errorCode=24 Authorization failed.

服务器需要用户名和密码(退出码 24)。

解决方法

用 --http-user=用户名 --http-passwd=密码 传入(FTP:--ftp-user、--ftp-passwd)。我们确认这样可以解决。

Too many redirects(重定向过多)

退出码 23
错误信息 · ✓ 已用 aria2 1.37.0 复现
errorCode=23 Too many redirects: count=20

服务器让 aria2 在循环中跳转;aria2 在 20 次重定向后放弃(退出码 23)。

解决方法

这通常说明网站需要登录 Cookie,一直跳转到登录页。转发 Cookie,或在浏览器中打开链接找到最终地址。

Timeout.(超时)

退出码 2
错误信息 · ✓ 已用 aria2 1.37.0 复现
errorCode=2 Timeout.

服务器接受了连接,但没有及时响应(退出码 2)。

解决方法

重试;对慢速服务器调高 --timeout 和 --connect-timeout,并设置 --max-tries=0 持续重试。

Failed to establish connection, cause: Connection refused(连接被拒绝)

退出码 1
错误信息 · ✓ 已用 aria2 1.37.0 复现
errorCode=1 Failed to establish connection, cause: Connection refused

该主机和端口上没有程序在监听,或被防火墙拒绝。如果设置了代理,也可能是代理本身挂了。

解决方法

检查地址和端口。如果使用了 --all-proxy 或代理环境变量,先检查代理。

Name resolution failed(域名解析失败)

退出码 19
错误信息 · ✓ 已用 aria2 1.37.0 复现
errorCode=19 Name resolution for no-such-host.invalid failed:Domain name not found

aria2 无法解析主机名(退出码 19)。

解决方法

检查拼写和 DNS。如果网络中的 IPv6 有问题,--disable-ipv6=true 往往有效;--async-dns=false 会让 aria2 使用系统解析器。

Invalid range header(分段请求无效)

退出码 8
错误信息 · ✓ 已用 aria2 1.37.0 复现
errorCode=8 Invalid range header. Request: 1048576-2097151/2097152, Response: 0-2097151/2097152

服务器忽略分段请求,总是返回整个文件。多连接下载会退回到单连接,也无法续传(需要续传时退出码为 8)。

解决方法

你这边无需修复:用 -x 1 一次下载完。在我们的测试中,下载仍以单连接完成了。

aria2 保存了一个小的 HTML 页面而不是文件

服务器返回了一个网页(登录页或链接过期提示)和成功状态,aria2 就把它保存了下来。

解决方法

用文本编辑器打开保存的文件看看内容。然后通过浏览器带 Cookie 发送下载,或获取新链接。

下载速度远低于我的带宽

通常是每个服务器只用一个连接(aria2 的默认值),或 min-split-size 对这个文件来说太大。

解决方法

使用 -x 16 -s 16 -k 1M。我们的速度优化指南给出了实测结果和其他瓶颈。

TLS / SSL

SSL/TLS handshake failure:not signed by known authorities(证书无法验证)

退出码 1
错误信息 · ✓ 已用 aria2 1.37.0 复现
errorCode=1 SSL/TLS handshake failure:  `not signed by known authorities or invalid' `issuer is not known'

aria2 无法验证服务器证书:它是自签名的、由私有 CA 签发的,或者你缺少 CA 证书包。

解决方法

让 aria2 使用正确的 CA 文件:--ca-certificate=/path/ca.pem。安装系统的 CA 证书软件包。仅对你信任的服务器,可用 --check-certificate=false 跳过检查。两种方法我们都测试过。

文件与磁盘

File exists, but a control file (*.aria2) does not exist(文件已存在但没有控制文件)

退出码 13
错误信息 · ✓ 已用 aria2 1.37.0 复现
errorCode=13 File big.bin exists, but a control file(*.aria2) does not exist. Download was canceled in order to prevent your file from being truncated to 0.

在 --allow-overwrite=false 和 --auto-file-renaming=false 时,aria2 拒绝触碰一个它没有进度记录的已有文件(退出码 13)。

解决方法

删除或移走旧文件,或加上 --allow-overwrite=true。多连接下载后不要用 -c 去“续传”它;参见 .aria2 文件测试。

Failed to make the directory(无法创建目录)

退出码 18
错误信息 · ✓ 已用 aria2 1.37.0 复现
errorCode=18 Failed to make the directory /etc/passwd, cause: File exists

下载目录无法创建:有同名文件、路径只读,或没有权限(退出码 18)。

解决方法

检查 dir。确保上级文件夹存在,并且运行 aria2 的用户(Docker 中为容器用户)可以写入。

Detected a change in piece length(分块大小变化)

退出码 10
错误信息 · ✓ 已用 aria2 1.37.0 复现
errorCode=10 WARNING: Detected a change in piece length. You can proceed with --allow-piece-length-change=true, but you may lose some download progress.

你续传时用的 --piece-length 与写入 .aria2 文件时不同(退出码 10)。

解决方法

用原来的设置续传,或加上 --allow-piece-length-change=true 并接受丢失部分进度。

Checksum error detected(校验和错误)

退出码 32
错误信息 · ✓ 已用 aria2 1.37.0 复现
Checksum error detected. file=ck.bin

下载完成的文件与你给出的 --checksum 不一致(退出码 32)。

解决方法

确认这个哈希值确实属于这个文件。要修复,用相同的 --checksum 加 -V -c 再运行一次,aria2 会重新下载有问题的部分。

磁盘空间不足

退出码 9

磁盘满了(退出码 9)。使用 file-allocation=prealloc 或 falloc 时,aria2 在开始前就需要完整大小的空间。

解决方法

释放空间或换一个 dir。file-allocation=none 可以不预留空间就开始下载,但之后仍可能空间不足。

在 U 盘或 SD 卡上到 4 GB 就失败

FAT32 无法存储 4 GiB 及以上的文件。

解决方法

把磁盘格式化为 exFAT 或 NTFS,或保存到其他磁盘。在这类磁盘上使用 file-allocation=none。

下载又从 0% 开始

.aria2 控制文件不见了,或文件被保存到了别处。

解决方法

在同一个文件夹中、以相同的文件名运行相同的命令。.aria2 文件指南列出了 11 种实测情况。

RPC 与 WebUI

Failed to bind a socket … Address already in use(端口被占用)

退出码 1
错误信息 · ✓ 已用 aria2 1.37.0 复现
IPv4 RPC: failed to bind TCP port 6800
errorCode=1 Failed to bind a socket, cause: Address already in use

另一个 aria2(或其他程序)已经占用了 6800 端口。

解决方法

停止另一个实例,或用 --rpc-listen-port=6801 启动这一个,并连接那个端口。

IPv6 RPC: failed to bind TCP port 6800

错误信息 · ✓ 已用 aria2 1.37.0 复现
IPv6 RPC: failed to bind TCP port 6800

在 IPv6 关闭时(比如大多数 Docker 容器)这条信息无害。它前一行表示 IPv4 监听正常。

解决方法

无需处理。只有当还出现 IPv4 RPC: failed to bind 时,端口才是真的被占用了。

RPC 返回 "Unauthorized"

错误信息 · ✓ 已用 aria2 1.37.0 复现
{"code":1,"message":"Unauthorized"}

客户端发送的密钥与 --rpc-secret 不一致。连接本身是通的。

解决方法

在客户端中填写与 rpc-secret 完全相同的值。直接调用时,它是第一个参数:"token:密钥"。

RPC 返回 "Parse error."

错误信息 · ✓ 已用 aria2 1.37.0 复现
{"code":-32700,"message":"Parse error."}

请求体不是有效的 JSON,通常是 shell 引号的问题。

解决方法

在 shell 中用单引号包住 JSON,并检查逗号和括号。在 Windows PowerShell 中,请用 Invoke-RestMethod 加 body,而不是 curl 的引号写法。

No such method(没有这个方法)

错误信息 · ✓ 已用 aria2 1.37.0 复现
{"code":1,"message":"No such method: aria2.nope"}

方法名拼错了,或缺少 aria2. 前缀。

解决方法

方法名形如 aria2.addUri 和 aria2.tellActive。system.listMethods 会列出全部方法。

BitTorrent 与链接

Unrecognized URI or unsupported protocol(无法识别的链接)

退出码 1
错误信息 · ✓ 已用 aria2 1.37.0 复现
errorCode=1 Unrecognized URI or unsupported protocol: magnet:?xt=urn:btih:zzzz

aria2 无法使用你提供的内容:有错字、磁力链接格式不对,或文件路径不存在。

解决方法

磁力链接在 xt=urn:btih: 后需要 40 位十六进制或 32 位 base32 哈希。在 shell 中,包含 & 的链接要加引号。如果是文件,请检查路径。

Bencode decoding failed(种子文件解析失败)

退出码 25
错误信息 · ✓ 已用 aria2 1.37.0 复现
errorCode=25 Bencode decoding failed

.torrent 文件已损坏或根本不是种子,常见的是以该名称保存的 HTML 页面(退出码 25)。

解决方法

重新下载 .torrent,或改用磁力链接。

Could not parse Metalink XML document(Metalink 解析失败)

退出码 20
错误信息 · ✓ 已用 aria2 1.37.0 复现
errorCode=20 Could not parse Metalink XML document.

.metalink 或 .meta4 文件已损坏(退出码 20)。

解决方法

重新下载;用文本编辑器打开,看看它是否真的是 XML。

磁力链接在开始下载前卡住

aria2 需要先从节点获取种子的元数据,但还没找到节点。

解决方法

解决方法与 0 个节点相同:Tracker 和 DHT。加上 --bt-save-metadata=true,元数据一到就会保存为 .torrent。

下载完成后 aria2 一直在做种

aria2 会做种直到分享率达到 seed-ratio(默认 1.0);分享率为 0.0 时会一直做种。

解决方法

设置 seed-time=0 在下载后立即停止,或设置分享率,例如 seed-ratio=1.0。

aria2 退出码

aria2 返回它遇到的最后一个错误的代码(来自官方手册)。已完成下载中的错误不会被报告。

代码含义参见
0 所有下载都成功
1 未知错误(连接、TLS 和 RPC 端口错误也用它)
2 超时 Timeout.(超时)
3 资源不存在 Resource not found(404)
4 “资源不存在”达到 --max-file-not-found 次数
5 速度过慢:--lowest-speed-limit
6 网络问题
7 aria2 停止时(Ctrl+C)还有未完成的下载
8 服务器不支持续传,但需要续传 Invalid range header(分段请求无效)
9 磁盘空间不足 磁盘空间不足
10 分块大小与 .aria2 文件不同 Detected a change in piece length(分块大小变化)
11 aria2 已在下载同一个文件
12 aria2 已在下载同一个种子
13 文件已存在 File exists, but a control file (*.aria2) does not exist(文件已存在但没有控制文件)
14 重命名文件失败
15 无法打开已有文件
16 无法创建或截断文件 Failed to open the file … No such file or directory / Permission denied(无法创建文件)
17 文件读写错误
18 无法创建目录 Failed to make the directory(无法创建目录)
19 域名解析失败 Name resolution failed(域名解析失败)
20 无法解析 Metalink 文件 Could not parse Metalink XML document(Metalink 解析失败)
21 FTP 命令失败
22 HTTP 响应异常(403、429 也是它) status=403(禁止访问)
23 重定向过多 Too many redirects(重定向过多)
24 HTTP 认证失败 Authorization failed(401,认证失败)
25 无法解析 bencode(.torrent)文件 Bencode decoding failed(种子文件解析失败)
26 .torrent 文件损坏或不完整
27 磁力链接无效
28 选项或选项值错误 Parse error in aria2.conf(配置文件解析错误)
29 服务器暂时过载或维护中(503) status=503(服务不可用)
30 无法解析 JSON-RPC 请求
31 保留,未使用
32 校验和验证失败 Checksum error detected(校验和错误)

相关资源