huggingface_hub.utils._errors.HfHubHTTPError: 401 Client Error:成功解决

问题描述

先看报错(解决办法在最后):下面这个图片是完整的错误信息,但是主要的就是这么几行:

requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://hf-mirror.com/api/repos/create

huggingface_hub.utils._errors.HfHubHTTPError: 401 Client Error: Unauthorized for url: https://hf-mirror.com/api/repos/create (Request ID: Root=1-672e0459-25edb7244f5d7c5e665530cc;fdb33069-8100-4967-a736-419b2d7a126e)

Invalid username or password.
在这里插入图片描述

解决办法

大概意思就是说,Seq2SeqTrainer这个类中某个文件的代码会去访问huggingface,并且是需要token的,这个token需要自己创建一个huggingface账号,在个人主页中的Access Tokens 页面创建一个token就行。
然后在自己的代码最前面加入以下几行:

from huggingface_hub import login

# 输入你的 Hugging Face 账户 Token,这里把自己的刚刚创建的token粘贴进来就行啦
login("your_huggingface_token")

(caption-env) root@ubuntu:~/models/MobileVLM-1.7B# export HF_ENDPOINT=https://hf-mirror.com (caption-env) root@ubuntu:~/models/MobileVLM-1.7B# huggingface-cli download MobileVLM/MobileVLM-1.7B-GGUF \ --include "mmproj-model-f16.gguf" \ --local-dir ./models Traceback (most recent call last): File "/root/caption-env/lib/python3.10/site-packages/huggingface_hub/utils/_http.py", line 409, in hf_raise_for_status response.raise_for_status() File "/root/caption-env/lib/python3.10/site-packages/requests/models.py", line 1026, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://hf-mirror.com/api/models/MobileVLM/MobileVLM-1.7B-GGUF/revision/main The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/root/caption-env/bin/huggingface-cli", line 8, in <module> sys.exit(main()) File "/root/caption-env/lib/python3.10/site-packages/huggingface_hub/commands/huggingface_cli.py", line 59, in main service.run() File "/root/caption-env/lib/python3.10/site-packages/huggingface_hub/commands/download.py", line 153, in run print(self._download()) # Print path to downloaded files File "/root/caption-env/lib/python3.10/site-packages/huggingface_hub/commands/download.py", line 187, in _download return snapshot_download( File "/root/caption-env/lib/python3.10/site-packages/huggingface_hub/utils/_validators.py", line 114, in _inner_fn return fn(*args, **kwargs) File "/root/caption-env/lib/python3.10/site-packages/huggingface_hub/_snapshot_download.py", line 245, in snapshot_download raise api_call_error File "/root/caption-env/lib/python3.10/site-packages/huggingface_hub/_snapshot_download.py", line 165, in snapshot_download repo_info = api.repo_info(repo_id=repo_id, repo_type=repo_type, revision=revision) File "/root/caption-env/lib/python3.10/site-packages/huggingface_hub/utils/_validators.py", line 114, in _inner_fn return fn(*args, **kwargs) File "/root/caption-env/lib/python3.10/site-packages/huggingface_hub/hf_api.py", line 2844, in repo_info return method( File "/root/caption-env/lib/python3.10/site-packages/huggingface_hub/utils/_validators.py", line 114, in _inner_fn return fn(*args, **kwargs) File "/root/caption-env/lib/python3.10/site-packages/huggingface_hub/hf_api.py", line 2629, in model_info hf_raise_for_status(r) File "/root/caption-env/lib/python3.10/site-packages/huggingface_hub/utils/_http.py", line 459, in hf_raise_for_status raise _format(RepositoryNotFoundError, message, response) from e huggingface_hub.errors.RepositoryNotFoundError: 401 Client Error. (Request ID: Root=1-686e1515-3beb98ac6fa889bc6c585014;e4999aad-8bdf-412a-b58e-6cf930bed578) Repository Not Found for url: https://hf-mirror.com/api/models/MobileVLM/MobileVLM-1.7B-GGUF/revision/main. Please make sure you specified the correct `repo_id` and `repo_type`. If you are trying to access a private or gated repo, make sure you are authenticated. For more details, see https://huggingface.co/docs/huggingface_hub/authentication Invalid username or password.
最新发布
07-10
<think>我们分析用户的问题:用户想要下载MobileVLM/MobileVLM-1.7B-GGUF模型,但在使用huggingface-cli命令时遇到了两个问题: 1. 之前的命令中使用了`--repo-id`参数,但新版本的huggingface-cli已经不再支持这个参数,导致报错。 2. 用户可能遇到了401 Unauthorized错误,即认证失败。 根据引用[2]和引用[3],401错误通常是由于凭据(token)无效或过期导致的。因此,我们需要确保用户已经正确登录并提供了有效的token。 解决方案步骤: 1. 更新命令格式:去掉`--repo-id`,直接将模型仓库标识作为位置参数。 2. 确保用户已经登录Hugging Face,并且token有效。 具体操作如下: 步骤1:安装或更新huggingface_hub库 步骤2:使用huggingface-cli登录(如果尚未登录或token过期) 步骤3:使用正确的命令下载模型 注意:如果用户之前设置了镜像(如hf-mirror.com),则可能需要设置环境变量`HF_ENDPOINT`。 另外,根据引用[3],如果token过期,需要重新生成并登录。 因此,我们将提供以下解决方案:</think>### 解决 Hugging Face 模型下载的 401 Unauthorized 错误 您在使用 `huggingface-cli` 下载 MobileVLM/MobileVLM-1.7B-GGUF 模型时遇到的 401 错误是由于身份验证问题导致的[^2][^3]。以下是完整的解决方案: #### 步骤 1:更新下载命令语法 ```bash # 正确语法(移除废弃的 --repo-id 参数) huggingface-cli download \ MobileVLM/MobileVLM-1.7B-GGUF \ --revision main \ --include "mmproj-model-f16.gguf" \ --local-dir . ``` #### 步骤 2:解决 401 Unauthorized 错误 这是核心问题,需要身份验证: 1. **获取访问令牌**: - 访问 [Hugging Face 账户设置](https://huggingface.co/settings/tokens) - 点击 "New token" 创建新令牌 - 权限选择 "read" 即可(无需 write 权限) 2. **登录 Hugging Face CLI**: ```bash huggingface-cli login ``` - 粘贴刚才复制的访问令牌 - 出现 "Login successful" 表示认证成功 3. **接受模型使用协议**(关键步骤): - 访问模型页面:[MobileVLM-1.7B-GGUF](https://huggingface.co/MobileVLM/MobileVLM-1.7B-GGUF) - 点击 "Agree and continue" 接受使用协议 - **必须完成此步骤**,否则会持续收到 401 错误[^3] #### 步骤 3:验证下载(可选镜像加速) ```bash # 设置镜像端点(国内用户推荐) export HF_ENDPOINT=https://hf-mirror.com # 执行下载 huggingface-cli download MobileVLM/MobileVLM-1.7B-GGUF \ --include "mmproj-model-f16.gguf" \ --local-dir . ``` #### 常见错误排查 | 错误现象 | 解决方案 | |---------|----------| | `401 Unauthorized` | 1. 确认已登录 `huggingface-cli login`<br>2. 确认已接受模型使用协议 | | `Repository Not Found` | 检查模型名称拼写:`MobileVLM/MobileVLM-1.7B-GGUF` | | 下载中断 | 添加 `--resume-download` 参数启用断点续传 | | 权限不足 | 使用 `sudo chown -R $USER:$USER ./` 修复目录权限 | > **技术说明**:401 错误表示服务器无法验证请求者的身份。当 Hugging Face 检测到: > 1. 未提供有效访问令牌 > 2. 令牌已过期(默认有效期90天) > 3. 用户未接受模型使用协议 > 时会返回此状态码[^2][^3]。数学表示为: > $$ \text{HTTP Status} = \begin{cases} 401 & \text{if } \neg \text{validToken} \lor \text{tokenExpired} \\ 200 & \text{otherwise} \end{cases} $$
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值